本文整理汇总了PHP中Hash::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::normalize方法的具体用法?PHP Hash::normalize怎么用?PHP Hash::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
/**
* Setup
*
* Sets up the configuration for the model
*
* @author Paul Smith <paul@wizehive.com>
* @since 1.0
* @param Model $model
* @param array $config
* @return void
*/
public function setup(Model $Model, $settings = array())
{
foreach (array('json', 'serialized') as $type) {
if (isset($settings[$type])) {
// Automatically parse json & serialized field structure from model attributes
$settings[$type] = Hash::normalize($settings[$type]);
foreach ($settings[$type] as $field => $attribute) {
if (empty($attribute)) {
$settings[$type][$field] = $attribute = $field;
}
}
$modelAttributes = Hash::expand($Model->attributes());
foreach ($settings[$type] as $field => $attribute) {
$match = Hash::extract($modelAttributes, $attribute);
if (!empty($match)) {
$this->settings[$Model->alias][$type][$field] = $match;
}
}
} else {
$this->settings[$Model->alias][$type] = array();
}
}
$this->settings[$Model->alias]['virtual'] = isset($settings['virtual']) ? $settings['virtual'] : false;
$this->settings[$Model->alias]['callback'] = isset($settings['callback']) ? $settings['callback'] : false;
// Set up callback fields for this model
if ($this->settings[$Model->alias]['callback']) {
$this->__setupSpecialFields($Model, 'callback');
}
}
示例2: setup
/**
* {@inheritdoc}
*/
public function setup(Model $Model, $config = array())
{
if (empty($config)) {
$config = $this->_defaults;
}
$this->settings[$Model->alias] = Hash::normalize((array) $config);
}
示例3: testInstanceSetup
/**
* Test Instance Setup
*
* @author Everton Yoshitani <everton@wizehive.com>
* @since 1.0
* @return void
*/
public function testInstanceSetup()
{
$components = Hash::normalize($this->Permissions->components);
$this->assertArrayHasKey('Auth', $components);
$this->assertInstanceOf('AuthComponent', $this->Permissions->Auth);
$this->assertArrayHasKey('Acl', $components);
$this->assertInstanceOf('AclComponent', $this->Permissions->Acl);
}
示例4: setup
/**
* {@inheritdoc}
*/
public function setup(Model $Model, $config = array())
{
if (!empty($config) && (!array_key_exists('fields', (array) $config) && Hash::numeric((array) array_keys($config)))) {
$config = array('fields' => Hash::normalize($config));
}
$this->settings[$Model->alias] = array_merge($this->_defaults, $config);
$this->bindSecurityToken($Model);
}
示例5: testInstanceSetup
/**
* Test Instance Setup
*
* @author Everton Yoshitani <everton@wizehive.com>
* @since 1.0
* @return void
*/
public function testInstanceSetup()
{
// Test Components
$components = Hash::normalize($this->Api->components);
$this->assertArrayHasKey('Query', $components);
$this->assertArrayHasKey('InputData', $components);
$this->assertArrayHasKey('Permissions', $components);
$this->assertArrayHasKey('Resource', $components);
$this->assertArrayHasKey('ApiPaginator', $components);
$this->assertArrayHasKey('ApiRequestHandler', $components);
}
示例6: constructLimits
public function constructLimits()
{
$global = array('callback' => array('flash', array('security.access_limit.fail')), 'duration' => '+1 hour', 'limit' => 5);
if (!empty($this->settings[AccessLimitComponent::ALL])) {
$global = array_merge($global, $this->settings[AccessLimitComponent::ALL]);
unset($this->settings[AccessLimitComponent::ALL]);
}
foreach ($this->settings as $requestType => $settings) {
$this->{$requestType} = array();
foreach (Hash::normalize($settings) as $action => $limit) {
if (!empty($limit) && !is_array($limit)) {
$limit = compact('limit');
}
$this->{$requestType}[$action] = array_merge($global, (array) $limit);
}
}
}
示例7: __construct
/**
* Overrides `Model::__construct()`.
*
* - Auto-load plugin behaviors using the 'Model.construct' event.
*
* @param integer|string|array $id Set this ID for this model on startup, can also be an array of options, see above.
* @param string $table Name of database table to use.
* @param string $ds DataSource connection name.
*/
public function __construct($id = false, $table = null, $ds = null)
{
parent::__construct($id, $table, $ds);
foreach (get_class_methods($this) as $method) {
$key = lcfirst(str_replace('_find', '', $method));
if (isset($this->findMethods[$key]) || strpos($method, '_find') !== 0) {
continue;
}
$ReflectionMethod = new ReflectionMethod($this, $method);
$params = $ReflectionMethod->getParameters();
foreach (array('state', 'query', 'results') as $k => $name) {
if ((array) $params[$k] != compact('name')) {
$key = null;
break;
}
}
if (!empty($key)) {
$this->findMethods[$key] = true;
}
}
if (empty($this->friendly)) {
$this->friendly = Inflector::humanize(Inflector::underscore($this->name));
}
$timer = 'modelConstruct' . $this->alias;
Common::startTimer($timer, __d('common', "Event: Model.construct (%s)", $this->alias));
$result = array_merge(array('actsAs' => array()), (array) $this->triggerEvent('Model.construct', $this));
$this->actsAs = Hash::merge(Hash::normalize((array) $result['actsAs']), Hash::normalize((array) $this->actsAs));
unset($result['actsAs']);
foreach ($this->actsAs as $name => $config) {
list(, $behavior) = pluginSplit($name);
if (!$this->Behaviors->loaded($behavior)) {
$this->Behaviors->load($name, $config);
}
}
$this->_set($result);
Common::stopTimer($timer);
}
示例8: _mergePropertyData
/**
* Merge each of the keys in a property together.
*
* @param array $current The current merged value.
* @param array $parent The parent class' value.
* @param bool $isAssoc Whether or not the merging should be done in associative mode.
* @return mixed The updated value.
*/
protected function _mergePropertyData($current, $parent, $isAssoc)
{
if (!$isAssoc) {
return array_merge($parent, $current);
}
$parent = Hash::normalize($parent);
foreach ($parent as $key => $value) {
if (!isset($current[$key])) {
$current[$key] = $value;
}
}
return $current;
}
示例9: getOptionParser
/**
* {@inheritdoc}
*
* @return ConsoleOptionParser
*/
public function getOptionParser()
{
$parser = parent::getOptionParser();
$parser->description('There is no help');
$taskNames = array_keys(Hash::normalize($this->tasks));
foreach ($taskNames as $taskName) {
$Task = $this->{$taskName};
$parser->addSubcommand(Inflector::underscore($Task->name), array('help' => $Task->getOptionParser()->description(), 'parser' => $Task->getOptionParser()));
}
return $parser;
}
示例10: constructClasses
/**
* Overrides `Controller::constructClasses()` to apply the 'Controller.constructClasses'
* event's results.
*
* @return void
*/
public function constructClasses()
{
$timer = 'controllerConstructClasses';
Common::startTimer($timer, __d('common', "Event: Controller.constructClasses"));
$properties = array('components', 'helpers');
$result = $this->triggerEvent('Controller.constructClasses', $this);
$this->_mergeControllerVars();
foreach ($properties as $property) {
if (!isset($result[$property])) {
continue;
}
$this->{$property} = Hash::merge(Hash::normalize($result[$property]), Hash::normalize((array) $this->{$property}));
unset($result[$property]);
}
$this->_set($result);
Common::stopTimer($timer);
parent::constructClasses();
}
示例11: _normalizeConfig
/**
* Normalize action configuration
*
* If an action doesn't have a CrudClass specified (the value part of the array)
* try to compute it by exploding on action name on '_' and take the last chunk
* as CrudClass identifier.
*
* @param mixed $types Class type(s).
* @return void
* @throws CakeException If className is missing for listener.
*/
protected function _normalizeConfig($types = null)
{
if (!$types) {
$types = array('listeners', 'actions');
}
foreach ((array) $types as $type) {
$this->settings[$type] = Hash::normalize($this->settings[$type]);
foreach ($this->settings[$type] as $name => $settings) {
if (is_array($settings) && !empty($settings['className'])) {
$this->settings[$type][$name] = $settings;
continue;
}
$className = null;
if (empty($settings)) {
$settings = array();
} elseif (is_string($settings)) {
$className = $settings;
$settings = array();
}
if ($type === 'listeners' && strpos($name, '.') !== false) {
unset($this->settings[$type][$name]);
$settings['className'] = $name;
list($plugin, $name) = pluginSplit($name);
$name = Inflector::camelize($name);
}
$className = $this->_handlerClassName($name, $className);
if (empty($settings['className'])) {
$settings['className'] = $className;
}
$this->settings[$type][$name] = $settings;
}
}
}
示例12: unbindModel
/**
* Turn off associations on the fly.
*
* If $reset is false, association will not be reset
* to the originals defined in the model
*
* Example: Turn off the associated Model Support request,
* to temporarily lighten the User model:
*
* `$this->User->unbindModel(array('hasMany' => array('SupportRequest')));`
* Or alternatively:
* `$this->User->unbindModel(array('hasMany' => 'SupportRequest'));`
*
* Unbound models that are not made permanent will reset with the next call to Model::find()
*
* @param array $params Set of bindings to unbind (indexed by binding type)
* @param bool $reset Set to false to make the unbinding permanent
*
* @return bool Success
* @link http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#creating-and-destroying-associations-on-the-fly
*/
public function unbindModel($params, $reset = TRUE)
{
foreach ($params as $assoc => $models) {
if ($reset === TRUE && !isset($this->__backAssociation[$assoc])) {
$this->__backAssociation[$assoc] = $this->{$assoc};
}
$models = Hash::normalize((array) $models, FALSE);
foreach ($models as $model) {
if ($reset === FALSE && isset($this->__backAssociation[$assoc][$model])) {
unset($this->__backAssociation[$assoc][$model]);
}
unset($this->{$assoc}[$model]);
}
}
return TRUE;
}
示例13: testAttributes
/**
* Test Attributes
*
* @author Everton Yoshitani <everton@wizehive.com>
* @since 1.0
* @return void
*/
public function testAttributes()
{
$this->TestModel->expects($this->exactly(2))->method('schema')->with()->will($this->returnValue(array('some_field' => array('type' => 'integer'), 'some_other_field' => array('type' => 'string'), 'created' => array('type' => 'datetime'))));
$attributes = $this->TestModel->_attributes;
$attributes['someAttribute'] = array('field' => 'some_field');
$attributes['someOtherAttribute'] = array('field' => 'some_other_field');
$attributes['created'] = array();
$expected = Hash::normalize($attributes);
$expected['someAttribute']['type'] = 'int';
$expected['someOtherAttribute']['type'] = 'string';
$expected['created'] = array('field' => 'created', 'type' => 'datetime');
$result = $this->ApiBehavior->attributes($this->TestModel, $attributes);
$this->assertEquals($expected, $result);
$result = $this->ApiBehavior->attributes($this->TestModel);
$this->assertEquals($expected, $result);
}
示例14: _walkMap
/**
* ApiComponent::$recordMapを走査するためのヘルパーメソッドです。
*
* @param callable $callback
* @return void
*/
protected function _walkMap(callable $callback)
{
foreach ($this->recordMap as $alias => $map) {
$map = Hash::normalize($map);
$wrap = null;
if (array_key_exists('_wrap', $map)) {
$wrap = $map['_wrap'];
unset($map['_wrap']);
}
foreach ($map as $recordField => $paramsField) {
if (!is_array($paramsField) && !$paramsField) {
$paramsField = $recordField;
}
$callback($paramsField, $alias, $recordField, $wrap);
}
}
}
示例15: config
/**
* Normalizes and sets config options as properties
*/
public function config()
{
if (empty($this->options['models'])) {
return;
}
$this->models = Hash::normalize($this->options['models']);
if (isset($this->options['prependPk'])) {
$this->prependPk = $this->options['prependPk'];
}
if (isset($this->options['slugFunction'])) {
$this->slugFunction = $this->options['slugFunction'];
}
}