本文整理汇总了PHP中Cake\Database\Type类的典型用法代码示例。如果您正苦于以下问题:PHP Type类的具体用法?PHP Type怎么用?PHP Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: initialize
/**
* JsonableBehavior::initialize()
*
* @param array $config
* @return void
*/
public function initialize(array $config = [])
{
Type::map('array', 'Tools\\Database\\Type\\ArrayType');
if (empty($this->_config['fields'])) {
throw new Exception('Fields are required');
}
if (!is_array($this->_config['fields'])) {
$this->_config['fields'] = (array) $this->_config['fields'];
}
if (!is_array($this->_config['map'])) {
$this->_config['map'] = (array) $this->_config['map'];
}
if (!empty($this->_config['map']) && count($this->_config['fields']) !== count($this->_config['map'])) {
throw new Exception('Fields and Map need to be of the same length if map is specified.');
}
foreach ($this->_config['fields'] as $field) {
$this->_table->schema()->columnType($field, 'array');
}
}
开发者ID:alescx,项目名称:cakephp-tools,代码行数:25,代码来源:JsonableBehavior.php
示例17: initialize
/**
* Initialize hook
*
* @param array $config The config for this behavior.
* @return void
*/
public function initialize(array $config)
{
$configs = [];
foreach ($config as $field => $settings) {
if (is_int($field)) {
$configs[$settings] = [];
} else {
$configs[$field] = $settings;
}
}
$this->config($configs);
$this->config('className', null);
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:josegonzalez,项目名称:cakephp-upload,代码行数:25,代码来源:UploadBehavior.php
示例18: initialize
/**
* @param array $config
* @throws \Exception
* @return void
*/
public function initialize(array $config = [])
{
if (empty($this->_config['fields'])) {
throw new Exception('Fields are required');
}
if (!is_array($this->_config['fields'])) {
$this->_config['fields'] = (array) $this->_config['fields'];
}
if (!is_array($this->_config['map'])) {
$this->_config['map'] = (array) $this->_config['map'];
}
if (!empty($this->_config['map']) && count($this->_config['fields']) !== count($this->_config['map'])) {
throw new Exception('Fields and Map need to be of the same length if map is specified.');
}
foreach ($this->_config['fields'] as $field) {
$this->_table->schema()->columnType($field, 'array');
}
if ($this->_config['encodeParams']['options'] === null) {
$options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_ERROR_INF_OR_NAN | JSON_PARTIAL_OUTPUT_ON_ERROR;
$this->_config['encodeParams']['options'] = $options;
}
Type::map('array', ArrayType::class);
}
开发者ID:dereuromark,项目名称:cakephp-tools,代码行数:28,代码来源:JsonableBehavior.php
示例19:
* Inflector::rules('transliteration', ['/å/' => 'aa']);
*/
/**
* Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
* Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more
* advanced ways of loading plugins
*
* Plugin::loadAll(); // Loads all plugins at once
* Plugin::load('Migrations'); //Loads a single plugin named Migrations
*
*/
Plugin::load('Migrations');
// Only try to load DebugKit in development mode
// Debug Kit should not be installed on a production system
if (Configure::read('debug')) {
Plugin::load('DebugKit', ['bootstrap' => true]);
}
/**
* Connect middleware/dispatcher filters.
*/
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
/**
* Enable default locale format parsing.
* This is needed for matching the auto-localized string output of Time() class when parsing dates.
*/
Type::build('date')->useLocaleParser();
Type::build('datetime')->useLocaleParser();
Plugin::load('BoxManager', ['bootstrap' => false, 'routes' => true]);
Plugin::load('SocialManager', ['bootstrap' => false, 'routes' => true]);
开发者ID:Aerue,项目名称:avalia,代码行数:31,代码来源:bootstrap.php
示例20: merge
/**
* Merges `$data` into `$entity` and recursively does the same for each one of
* the association names passed in `$options`. When merging associations, if an
* entity is not present in the parent entity for a given association, a new one
* will be created.
*
* When merging HasMany or BelongsToMany associations, all the entities in the
* `$data` array will appear, those that can be matched by primary key will get
* the data merged, but those that cannot, will be discarded. `ids` option can be used
* to determine whether the association must use the `_ids` format.
*
* ### Options:
*
* - associated: Associations listed here will be marshalled as well.
* - validate: Whether or not to validate data before hydrating the entities. Can
* also be set to a string to use a specific validator. Defaults to true/default.
* - fieldList: A whitelist of fields to be assigned to the entity. If not present
* the accessible fields list in the entity will be used.
* - accessibleFields: A list of fields to allow or deny in entity accessible fields.
*
* The above options can be used in each nested `associated` array. In addition to the above
* options you can also use the `onlyIds` option for HasMany and BelongsToMany associations.
* When true this option restricts the request data to only be read from `_ids`.
*
* ```
* $result = $marshaller->merge($entity, $data, [
* 'associated' => ['Tags' => ['onlyIds' => true]]
* ]);
* ```
*
* @param \Cake\Datasource\EntityInterface $entity the entity that will get the
* data merged in
* @param array $data key value list of fields to be merged into the entity
* @param array $options List of options.
* @return \Cake\Datasource\EntityInterface
*/
public function merge(EntityInterface $entity, array $data, array $options = [])
{
list($data, $options) = $this->_prepareDataAndOptions($data, $options);
$propertyMap = $this->_buildPropertyMap($options);
$isNew = $entity->isNew();
$keys = [];
if (!$isNew) {
$keys = $entity->extract((array) $this->_table->primaryKey());
}
if (isset($options['accessibleFields'])) {
foreach ((array) $options['accessibleFields'] as $key => $value) {
$entity->accessible($key, $value);
}
}
$errors = $this->_validate($data + $keys, $options, $isNew);
$schema = $this->_table->schema();
$properties = $marshalledAssocs = [];
foreach ($data as $key => $value) {
if (!empty($errors[$key])) {
if ($entity instanceof InvalidPropertyInterface) {
$entity->invalid($key, $value);
}
continue;
}
$columnType = $schema->columnType($key);
$original = $entity->get($key);
if (isset($propertyMap[$key])) {
$assoc = $propertyMap[$key]['association'];
$value = $this->_mergeAssociation($original, $assoc, $value, $propertyMap[$key]);
$marshalledAssocs[$key] = true;
} elseif ($columnType) {
$converter = Type::build($columnType);
$value = $converter->marshal($value);
$isObject = is_object($value);
if (!$isObject && $original === $value || $isObject && $original == $value) {
continue;
}
}
$properties[$key] = $value;
}
if (!isset($options['fieldList'])) {
$entity->set($properties);
$entity->errors($errors);
foreach (array_keys($marshalledAssocs) as $field) {
if ($properties[$field] instanceof EntityInterface) {
$entity->dirty($field, $properties[$field]->dirty());
}
}
return $entity;
}
foreach ((array) $options['fieldList'] as $field) {
if (array_key_exists($field, $properties)) {
$entity->set($field, $properties[$field]);
if ($properties[$field] instanceof EntityInterface && isset($marshalledAssocs[$field])) {
$entity->dirty($field, $properties[$field]->dirty());
}
}
}
$entity->errors($errors);
return $entity;
}
开发者ID:rlugojr,项目名称:cakephp,代码行数:97,代码来源:Marshaller.php
注:本文中的Cake\Database\Type类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论