当前位置: 首页>>代码示例>>PHP>>正文


PHP Database\Type类代码示例

本文整理汇总了PHP中Cake\Database\Type的典型用法代码示例。如果您正苦于以下问题:PHP Type类的具体用法?PHP Type怎么用?PHP Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeFilter

 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $session = $this->request->session();
     $lang = 'en';
     if (isset($this->request->params['lang'])) {
         $lang = $this->request->params['lang'];
     } else {
         if ($session->check('Config.language')) {
             $lang = $session->read('Config.language');
         }
     }
     $session->write('Config.language', $lang);
     // Change current language by post request
     if ($this->request->is('post') && isset($this->request->data['language'])) {
         $newLang = $this->request->data['language'];
         $transUrl = $this->translateUrl($newLang);
         $this->redirect($transUrl);
     }
     $this->set('lang', $lang);
     $this->set('controller', $this->name);
     I18n::locale($lang);
     Time::setToStringFormat('YYYY-MM-dd HH:mm:ss');
     Type::build('datetime')->useLocaleParser();
     $this->Auth->config(['unauthorizedRedirect' => false]);
     $this->Auth->allow(['login', 'init']);
     $user = $this->Auth->user();
     if (isset($user)) {
         $username = $user['username'];
         $this->set(['is_authorized' => true, 'username' => $username]);
     } else {
         $this->set('is_authorized', false);
     }
 }
开发者ID:GreeNoir,项目名称:game-wizard,代码行数:34,代码来源:AppController.php

示例2: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->type = Type::build('encryptedsecurity');
     $this->driver = $this->getMockBuilder('Cake\\Database\\Driver')->getMock();
     $this->crypted = base64_encode(Security::encrypt('string', Configure::read('Security.key')));
 }
开发者ID:Xety,项目名称:Xeta,代码行数:12,代码来源:EncryptedSecurityTypeTest.php

示例3: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Type::map('binary', BinaryType::class);
     $this->type = Type::build('binary');
     $this->driver = $this->getMockBuilder(Driver::class)->getMock();
 }
开发者ID:dereuromark,项目名称:cakephp-shim,代码行数:12,代码来源:BinaryTypeTest.php

示例4: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->type = Type::build('float');
     $this->driver = $this->getMock('Cake\\Database\\Driver');
     $this->locale = I18n::locale();
     I18n::locale($this->locale);
 }
开发者ID:HarkiratGhotra,项目名称:cake,代码行数:13,代码来源:FloatTypeTest.php

示例5: _buildPropertyMap

 /**
  * Build the map of property => marshalling callable.
  *
  * @param array $data The data being marshalled.
  * @param array $options List of options containing the 'associated' key.
  * @throws \InvalidArgumentException When associations do not exist.
  * @return array
  */
 protected function _buildPropertyMap($data, $options)
 {
     $map = [];
     $schema = $this->_table->schema();
     // Is a concrete column?
     foreach (array_keys($data) as $prop) {
         $columnType = $schema->columnType($prop);
         if ($columnType) {
             $map[$prop] = function ($value, $entity) use($columnType) {
                 return Type::build($columnType)->marshal($value);
             };
         }
     }
     // Map associations
     if (!isset($options['associated'])) {
         $options['associated'] = [];
     }
     $include = $this->_normalizeAssociations($options['associated']);
     foreach ($include as $key => $nested) {
         if (is_int($key) && is_scalar($nested)) {
             $key = $nested;
             $nested = [];
         }
         $assoc = $this->_table->association($key);
         // If the key is not a special field like _ids or _joinData
         // it is a missing association that we should error on.
         if (!$assoc) {
             if (substr($key, 0, 1) !== '_') {
                 throw new \InvalidArgumentException(sprintf('Cannot marshal data for "%s" association. It is not associated with "%s".', $key, $this->_table->alias()));
             }
             continue;
         }
         if (isset($options['forceNew'])) {
             $nested['forceNew'] = $options['forceNew'];
         }
         if (isset($options['isMerge'])) {
             $callback = function ($value, $entity) use($assoc, $nested) {
                 $options = $nested + ['associated' => []];
                 return $this->_mergeAssociation($entity->get($assoc->property()), $assoc, $value, $options);
             };
         } else {
             $callback = function ($value, $entity) use($assoc, $nested) {
                 $options = $nested + ['associated' => []];
                 return $this->_marshalAssociation($assoc, $value, $options);
             };
         }
         $map[$assoc->property()] = $callback;
     }
     $behaviors = $this->_table->behaviors();
     foreach ($behaviors->loaded() as $name) {
         $behavior = $behaviors->get($name);
         if ($behavior instanceof PropertyMarshalInterface) {
             $map += $behavior->buildMarshalMap($this, $map, $options);
         }
     }
     return $map;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:65,代码来源:Marshaller.php

示例6: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->type = Type::build('float');
     $this->driver = $this->getMockBuilder('Cake\\Database\\Driver')->getMock();
     $this->locale = I18n::locale();
     $this->numberClass = FloatType::$numberClass;
     I18n::locale($this->locale);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:14,代码来源:FloatTypeTest.php

示例7: initialize

 /**
  * Build the behaviour
  *
  * @param array $config Passed configuration
  * @return void
  */
 public function initialize(array $config)
 {
     Type::map('proffer.file', '\\Proffer\\Database\\Type\\FileType');
     $schema = $this->_table->schema();
     foreach (array_keys($this->config()) as $field) {
         $schema->columnType($field, 'proffer.file');
     }
     $this->_table->schema($schema);
 }
开发者ID:edukondaluetg,项目名称:CakePHP3-Proffer,代码行数:15,代码来源:ProfferBehavior.php

示例8: initialize

 /**
  * Initialize hook
  *
  * @param array $config The config for this behavior.
  * @return void
  */
 public function initialize(array $config)
 {
     $this->config(Hash::normalize($config));
     Type::map('upload.file', 'Josegonzalez\\Upload\\Database\\Type\\FileType');
     $schema = $this->_table->schema();
     foreach (array_keys($this->config()) as $field) {
         $schema->columnType($field, 'upload.file');
     }
     $this->_table->schema($schema);
 }
开发者ID:jxav,项目名称:cakephp-upload,代码行数:16,代码来源:UploadBehavior.php

示例9: __construct

 /**
  * __construct
  *
  * @param Table $table Table.
  * @param array $config Config.
  */
 public function __construct(Table $table, array $config = [])
 {
     parent::__construct($table, $config);
     Type::map('Utils.File', 'Utils\\Database\\Type\\FileType');
     $schema = $table->schema();
     foreach ($this->getFieldList() as $field => $settings) {
         $schema->columnType($field, 'Utils.File');
     }
     $table->schema($schema);
     $this->_Table = $table;
 }
开发者ID:eAliwei,项目名称:cakephp-utils,代码行数:17,代码来源:UploadableBehavior.php

示例10: initialize

 /**
  * Initialize hook
  *
  * @param array $config The config for this behavior
  * @return void
  */
 public function initialize(array $config)
 {
     $this->_initializedConfig = $config;
     $this->config($config);
     Type::map('upload.file', 'Dala00\\Upload\\Database\\Type\\FileType');
     $schema = $this->_table->schema();
     foreach ($config['fields'] as $field => $settings) {
         $schema->columnType($field, 'upload.file');
     }
     $this->_table->schema($schema);
     $this->fileSystem(new DefaultFileSystem());
 }
开发者ID:dala00,项目名称:cakephp-simple-upload,代码行数:18,代码来源:UploadBehavior.php

示例11: _requiresToExpressionCasting

 /**
  * Returns an array with the types that require values to
  * be casted to expressions, out of the list of type names
  * passed as parameter.
  *
  * @param array $types List of type names
  * @return array
  */
 protected function _requiresToExpressionCasting($types)
 {
     $result = [];
     $types = array_filter($types);
     foreach ($types as $k => $type) {
         $object = Type::build($type);
         if ($object instanceof ExpressionTypeInterface) {
             $result[$k] = $object;
         }
     }
     return $result;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:20,代码来源:ExpressionTypeCasterTrait.php

示例12: lock

 /**
  * {@inheritDoc}
  *
  * @return void
  */
 public function lock($by = null, $session = null)
 {
     if ($this->isLocked() && $by !== $this->lockOwner()) {
         throw new LockingException('This entity is already locked');
     }
     $this->set('locked_time', Type::build('datetime')->marshal(time()));
     if ($by !== null) {
         $this->set('locked_by', $by);
     }
     if ($session !== null) {
         $this->set('locked_session', $session);
     }
 }
开发者ID:lorenzo,项目名称:row-locker,代码行数:18,代码来源:LockableTrait.php

示例13: __construct

 /**
  * Constructor
  *
  * Merges config with the default and store in the config property
  *
  * @param \Cake\ORM\Table $table The table this behavior is attached to.
  * @param array $config The config for this behavior.
  */
 public function __construct(Table $table, array $config = [])
 {
     if (isset($config['columns']) && is_string($config['columns'])) {
         $config['columns'] = [$config['columns']];
     }
     parent::__construct($table, $config);
     if (!Type::map('serialized')) {
         Type::map('serialized', 'CMS\\Database\\Type\\SerializedType');
     }
     foreach ($this->config('columns') as $column) {
         $this->_table->schema()->columnType($column, 'serialized');
     }
 }
开发者ID:quickapps-plugins,项目名称:cms,代码行数:21,代码来源:SerializableBehavior.php

示例14: initialize

 /**
  * Build the behaviour
  * @param array $config Passed configuration
  * @return void
  */
 public function initialize(array $config)
 {
     // get config
     $config = $this->_config;
     // load the file type & schema
     Type::map('unimatrix.file', '\\Unimatrix\\Utility\\Database\\Type\\FileType');
     $schema = $this->_table->schema();
     // go through each field and change the column type to our file type
     foreach ($config['fields'] as $field => $path) {
         $schema->columnType($field . $config['suffix'], 'unimatrix.file');
     }
     // update schema
     $this->_table->schema($schema);
 }
开发者ID:unimatrix,项目名称:cakephp-utility,代码行数:19,代码来源:UploadableBehavior.php

示例15: __construct

 /**
  * Builds the type map
  *
  * @param \Cake\Database\TypeMap $typeMap Contains the types to use for converting results
  * @param \Cake\Database\Driver $driver The driver to use for the type conversion
  */
 public function __construct(TypeMap $typeMap, Driver $driver)
 {
     $this->_driver = $driver;
     $map = $typeMap->toArray();
     $types = Type::buildAll();
     $result = [];
     foreach ($types as $k => $type) {
         if ($type instanceof OptionalConvertInterface && !$type->requiresToPhpCast()) {
             unset($types[$k]);
         }
     }
     foreach ($map as $field => $type) {
         if (isset($types[$type])) {
             $result[$field] = $types[$type];
         }
     }
     $this->_typeMap = $result;
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:24,代码来源:FieldTypeConverter.php


注:本文中的Cake\Database\Type类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。