本文整理汇总了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);
}
}
示例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')));
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
}
示例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');
}
}
示例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);
}
示例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;
}