本文整理汇总了PHP中Cake\Database\Type::build方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::build方法的具体用法?PHP Type::build怎么用?PHP Type::build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Type
的用法示例。
在下文中一共展示了Type::build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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')));
}
示例2: 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();
}
示例3: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->type = Type::build('datetime');
$this->driver = $this->getMock('Cake\\Database\\Driver');
$this->_originalMap = Type::map();
}
示例4: 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);
}
}
示例5: 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);
}
示例6: setUp
public function setUp()
{
parent::setUp();
$this->type = Type::build('money');
$this->driver = $this->getMock('Cake\\Database\\Driver');
$this->_originalLocale = Money::$defaultLocale;
$this->_originalMap = Type::map();
}
示例7: _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;
}
示例8: 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);
}
示例9: _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;
}
示例10: 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);
}
}
示例11: findDecrypted
/**
* Custom finder to retrieve decrypted values.
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Options.
* @return \Cake\ORM\Query
*/
public function findDecrypted(Query $query, array $options)
{
$options += ['fields' => []];
$mapper = function ($row) use($options) {
$driver = $this->_table->connection()->driver();
foreach ($this->config('fields') as $field => $type) {
if ($options['fields'] && !in_array($field, (array) $options['fields']) || !$row->has($field)) {
continue;
}
$cipher = $row->get($field);
$plain = $this->decrypt($cipher);
$row->set($field, Type::build($type)->toPHP($plain, $driver));
}
return $row;
};
$formatter = function ($results) use($mapper) {
return $results->map($mapper);
};
return $query->formatResults($formatter);
}
示例12: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->type = Type::build('string');
$this->driver = $this->getMockBuilder('Cake\\Database\\Driver')->getMock();
}
示例13: marshal
/**
* Marshalls flat data into PHP objects.
*
* @param mixed $value The value to convert
* @param string $type Type identifier, `integer`, `float`, etc
* @return mixed Converted value
*/
public function marshal($value, $type)
{
return Type::build($type)->marshal($value);
}
示例14:
* 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 immutable time objects in the ORM.
*
* You can enable default locale format parsing by adding calls
* to `useLocaleParser()`. This enables the automatic conversion of
* locale specific date formats. For details see
* @link http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
*/
Type::build('time')->useImmutable();
Type::build('date')->useImmutable();
Type::build('datetime')->useImmutable();
Plugin::load('AkkaFacebook', ['bootstrap' => false, 'routes' => true]);
示例15: _newId
/**
* Generate a primary key value for a new record.
*
* By default, this uses the type system to generate a new primary key
* value if possible. You can override this method if you have specific requirements
* for id generation.
*
* @param array $primary The primary key columns to get a new ID for.
* @return mixed Either null or the new primary key value.
*/
protected function _newId($primary)
{
if (!$primary || count((array) $primary) > 1) {
return null;
}
$typeName = $this->schema()->columnType($primary[0]);
$type = Type::build($typeName);
return $type->newId();
}