本文整理汇总了PHP中Hash::expand方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::expand方法的具体用法?PHP Hash::expand怎么用?PHP Hash::expand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::expand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
public function initialize(Controller $Controller)
{
parent::initialize($Controller);
if (!self::_isSiftable($Controller)) {
return;
}
if (empty($Controller->request->data['Sifter'])) {
if (empty($Controller->request->params['named'])) {
return true;
}
$Controller->request->params['named'] = Hash::expand($Controller->request->params['named']);
return self::_sift($Controller);
}
$Model = $Controller->{$Controller->modelClass};
$field = array_filter((array) $Model->sifterConfig('fields'));
if (self::_isAjax($Controller)) {
if (!array_key_exists($Controller->request->data['Sifter']['search_field'], $field) || empty($Controller->request->data['Sifter']['search_value'])) {
return true;
}
return self::_setAutoComplete($Controller, array($Controller->request->data['Sifter']['search_field'] => $field[$Controller->request->data['Sifter']['search_field']]));
} elseif ($Controller->request->is('post')) {
unset($Controller->request->data['Sifter']);
$url = array();
foreach (Hash::filter($Controller->request->data) as $model => $fields) {
foreach ($fields as $field => $data) {
$url[$model . '.' . $field] = $data;
}
}
return $Controller->redirect(Hash::merge($url, array_diff_key($Controller->request->params, array('plugin' => null, 'controller' => null, 'action' => null, 'named' => null, 'pass' => null))));
}
}
示例2: compute
public function compute($data, $delete = false)
{
$id = $this->getID();
foreach ($this->autoFields as $autoField) {
$values = [];
$unsetDepends0 = [];
foreach ($autoField['depends0'] as $depend) {
if (Hash::check($data, $depend)) {
$values[$depend] = Hash::get($data, $depend);
} else {
if (is_array($this->data) && Hash::check($this->data, $depend)) {
$values[$depend] = Hash::get($this->data, $depend);
} else {
$unsetDepends0[] = $depend;
}
}
}
if (!empty($unsetDepends0)) {
$data = $this->find('first', ['conditions' => [$this->name . '.id' => $id], 'fields' => $unsetDepends0, 'recursive' => 0]);
foreach ($unsetDepends0 as $depend) {
$values[$depend] = Hash::get($data, $depend);
}
}
foreach ($autoField['depends1'] as $modelName => $depends) {
if (!is_string($modelName) || empty($depends)) {
continue;
}
$model = $this->{$modelName};
$data = $this->{$modelName}->find('all', ['conditions' => [$modelName . '.' . Inflector::underscore($this->name) . '_id' => $id], 'fields' => $depends, 'recursive' => 0]);
$values[$modelName] = Hash::extract($data, '{n}.' . $modelName);
}
$this->set($autoField['name'], call_user_func($autoField['callback'], Hash::expand($values)));
}
}
示例3: wysiwyg
/**
* WYSIWYGの初期処理
*
* @param string $fieldName フィールド名("Modelname.fieldname"形式)
* @param array $attributes HTML属性のオプション配列
* @return string WYSIWYGのHTML
*/
public function wysiwyg($fieldName, $attributes = array())
{
$ngModel = Hash::expand(array($fieldName => 0));
$ngModel = NetCommonsAppController::camelizeKeyRecursive($ngModel);
$ngModel = Hash::flatten($ngModel);
$ngModel = array_flip($ngModel);
$defaultAttributes = array('type' => 'textarea', 'ui-tinymce' => 'tinymce.options', 'ng-model' => $ngModel[0], 'rows' => 10);
$attributes = Hash::merge($defaultAttributes, $attributes);
// wysiwygに関連する js読み込みを Wysiwygプラグインから行う
$html = '';
$html .= $this->wysiwygScript();
$html .= $this->NetCommonsForm->input($fieldName, $attributes);
return $html;
}
示例4: __processFiles
/**
* Process $_FILES
*
* @author Anthony Putignano <anthony@wizehive.com>
* @since 1.0
* @return void
*/
protected function __processFiles()
{
if (!empty($_FILES)) {
$dimensions = Hash::dimensions($_FILES);
if ($dimensions === 2) {
$this->Controller->request->data = Hash::merge($this->Controller->request->data, $_FILES);
} else {
foreach ($_FILES as $key => $data) {
$parsed = array();
foreach (array('name', 'type', 'tmp_name', 'error') as $file_key) {
$flattened = Hash::flatten($_FILES[$key][$file_key]);
foreach ($flattened as $flat_key => $flat_value) {
$reflattened = $key . '.' . $flat_key . '.' . $file_key;
$parsed[$reflattened] = $flat_value;
}
}
$parsed = Hash::expand($parsed);
$this->Controller->request->data = Hash::merge($this->Controller->request->data, $parsed);
}
}
}
}
示例5: admin_index
/**
* Returns an array of server specific options
*/
public function admin_index()
{
$globalOptions = $this->Option->find('all');
$serverID = Configure::read('server_id');
$serverOptions = $this->ServerOption->getServerOptions($serverID);
$changedServerOptions = array();
foreach ($serverOptions as $k => $v) {
$changedServerOptions[$v['ServerOption']['name']] = $v['ServerOption']['value'];
}
$globalOptions = Hash::flatten($globalOptions);
//Replace global option values with server option values
foreach ($changedServerOptions as $k => $v) {
$key = array_search($k, $globalOptions, true);
if ($key) {
$key = explode('.', $key);
$n = $key[0];
foreach ($globalOptions as $i) {
$globalOptions[$n . '.Option.value'] = $v;
}
}
}
$serverOptions = Hash::expand($globalOptions);
//Remove locked options
foreach ($serverOptions as $k => $v) {
if ($v['Option']['locked'] == 1) {
unset($serverOptions[$k]);
}
}
//pr($serverOptions);
if ($this->request->is('requested')) {
return $serverOptions;
} else {
$this->set('serverOptions', $serverOptions);
}
$serverName = $this->getServerName($serverID);
$this->set('serverName', $serverName);
return null;
}
示例6: reformatContain
/**
* Reformat `contain` array
*
* @param array|string $contain The value of `contain` option of the query
* @return array
*/
private function reformatContain($contain)
{
// @codingStandardsIgnoreLine
$result = array('options' => array(), 'contain' => array());
$contain = (array) $contain;
foreach ($contain as $key => $val) {
if (is_int($key)) {
$key = $val;
$val = array();
}
if (!isset($this->containOptions[$key])) {
if (strpos($key, '.') !== false) {
$expanded = Hash::expand(array($key => $val));
list($key, $val) = each($expanded);
}
$ref =& $result['contain'][$key];
$ref = Hash::merge((array) $ref, $this->reformatContain($val));
} else {
$result['options'][$key] = $val;
}
}
return $result;
}
示例7: _getQuestionnaires
/**
* _getQuestionnaires
*
* @param string $folderPath path string to import zip file exist
* @param array $questionnaires questionnaire data in import json file
* @param $importKey import key (hash string)
* @return array QuestionnaireData
*/
protected function _getQuestionnaires($folderPath, $questionnaires, $importKey)
{
foreach ($questionnaires as &$q) {
// id, keyはクリアする
$this->Questionnaire->clearQuestionnaireId($q);
// WysIsWygのデータを入れなおす
$flatQuestionnaire = Hash::flatten($q);
foreach ($flatQuestionnaire as $key => &$value) {
$model = null;
if (strpos($key, 'QuestionnaireQuestion.') !== false) {
$model = $this->QuestionnaireQuestion;
} else {
if (strpos($key, 'QuestionnairePage.') !== false) {
$model = $this->QuestionnairePage;
} else {
if (strpos($key, 'Questionnaire.') !== false) {
$model = $this->Questionnaire;
}
}
}
if (!$model) {
continue;
}
$columnName = substr($key, strrpos($key, '.') + 1);
if ($model->hasField($columnName)) {
if ($model->getColumnType($columnName) == 'text') {
// keyと同じ名前のフォルダの下にあるkeyの名前のZIPファイルを渡して
// その返ってきた値をこのカラムに設定
$value = $this->QuestionnairesWysIsWyg->getFromWysIsWygZIP($folderPath . DS . $key . DS . $key . '.zip', $key);
}
}
}
$q = Hash::expand($flatQuestionnaire);
$q['Questionnaire']['import_key'] = $importKey;
}
return $questionnaires;
}
示例8: testSetValidationErrorsReset
/**
* Test Set Validation Errors - Reset
*
* @author Wes DeMoney <wes@wizehive.com>
* @since 1.0
* @return void
*/
public function testSetValidationErrorsReset()
{
$this->ApiResource->withFieldMap(array('username' => 'username'));
$this->ApiResource->setValidationIndex(array(0, 'ApiResourceComponentThing'));
$this->ApiResource->forModel('ApiResourceComponentThing')->setValidationErrors(array('username' => 'Please enter a username'));
$this->ApiResource->withFieldMap(array('id' => 'id', 'fname' => 'firstName', 'lname' => 'lastName'));
$this->ApiResource->setValidationIndex(array(0, 'ApiResourceComponentStuff'));
$this->ApiResource->forModel('ApiResourceComponentStuff')->setValidationErrors(array('fname' => 'Please enter a first name'));
$this->ApiResource->setValidationIndex(array(0, 'ApiResourceComponentThing'));
// Reset
$this->ApiResource->forModel('ApiResourceComponentThing')->setValidationErrors();
$this->ApiResource->withFieldMap(array('email' => 'email'));
$this->ApiResource->forModel('ApiResourceComponentThing')->setValidationErrors(array('email' => 'Please enter a valid email address'));
$this->assertEqual(array(array('apiResourceComponentThing' => array('email' => array('Please enter a valid email address')), 'apiResourceComponentStuff' => array('firstName' => array('Please enter a first name')))), Hash::expand($this->ApiResource->_validation_errors));
}
示例9: testExpand
/**
* Tests Hash::expand
*
* @return void
*/
public function testExpand()
{
$data = array('My', 'Array', 'To', 'Flatten');
$flat = Hash::flatten($data);
$result = Hash::expand($flat);
$this->assertEquals($data, $result);
$data = array('0.Post.id' => '1', '0.Post.author_id' => '1', '0.Post.title' => 'First Post', '0.Author.id' => '1', '0.Author.user' => 'nate', '0.Author.password' => 'foo', '1.Post.id' => '2', '1.Post.author_id' => '3', '1.Post.title' => 'Second Post', '1.Post.body' => 'Second Post Body', '1.Author.id' => '3', '1.Author.user' => 'larry', '1.Author.password' => null);
$result = Hash::expand($data);
$expected = array(array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post'), 'Author' => array('id' => '1', 'user' => 'nate', 'password' => 'foo')), array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body'), 'Author' => array('id' => '3', 'user' => 'larry', 'password' => null)));
$this->assertEquals($expected, $result);
$data = array('0/Post/id' => 1, '0/Post/name' => 'test post');
$result = Hash::expand($data, '/');
$expected = array(array('Post' => array('id' => 1, 'name' => 'test post')));
$this->assertEquals($result, $expected);
}
示例10: _getValidationErrors
/**
* バリデーションエラー
*
* @param Model $model 呼び出しもとのModel
* @param int $line 行数
* @return array
*/
protected function _getValidationErrors(Model $model, $line)
{
$flatten = Hash::flatten($model->validationErrors);
foreach ($flatten as $key => $message) {
$flatten[$key] = sprintf(__d('user_manager', 'Line %s: %s'), $line, $message);
}
return Hash::expand($flatten);
}
示例11: getSpecialFieldData
/**
* Retrieve Data for Special Fields
*
* @author Paul Smith <paul@wizehive.com>
* @since 1.0
* @param Model $Model
* @param array $result
* @return array
*/
public function getSpecialFieldData(Model $Model, $result)
{
$special_field_data = array();
// Fill out JSON/Serialized fields as appropriate
foreach (array('json', 'serialized') as $type) {
if (!empty($this->settings[$Model->alias][$type])) {
foreach ($this->settings[$Model->alias][$type] as $field => $sub_attributes) {
if (array_key_exists($field, $result[$Model->alias])) {
if ($type === 'json') {
$decoded = json_decode($result[$Model->alias][$field], true);
} else {
$decoded = unserialize($result[$Model->alias][$field]);
}
if (empty($decoded)) {
$special_field_data[$field] = null;
} elseif (array_key_exists('field', $sub_attributes) && array_key_exists('type', $sub_attributes)) {
$special_field_data[$field] = $decoded;
} else {
$decoded = Hash::flatten($decoded);
foreach ($decoded as $key => $value) {
foreach ($sub_attributes as $sub_attribute) {
$strlen = strlen($sub_attribute['field']) + 1;
if ($sub_attribute['field'] == $field . '.' . $key || $sub_attribute['field'] . '.' == substr($field . '.' . $key, 0, $strlen)) {
$special_field_data[$field][$key] = $value;
}
}
}
if (!empty($special_field_data[$field])) {
$special_field_data[$field] = Hash::expand($special_field_data[$field]);
}
}
}
}
}
}
// Get callback field values
if (!empty($this->settings[$Model->alias]['callbackFields'])) {
foreach ($this->settings[$Model->alias]['callbackFields'] as $callbackFieldName => $callbackFieldAttrs) {
if (!empty($this->_callbackFields) && !in_array($callbackFieldName, $this->_callbackFields)) {
continue;
}
$function = $callbackFieldAttrs['callbackFunction'];
if (!empty($callbackFieldAttrs['field'])) {
$callbackFieldName = $callbackFieldAttrs['field'];
}
if (method_exists($this, $function)) {
// If function is defined within this behavior, use that
$handler = array($this, $function);
array_unshift($callbackFieldAttrs['callbackParams'], $Model);
} elseif (method_exists($Model, $function)) {
// Otherwise use the function within the model itself
$handler = array($Model, $function);
}
$callback_params = array_merge(compact('result'), $callbackFieldAttrs['callbackParams']);
if (is_callable($handler)) {
$special_field_data[$callbackFieldName] = call_user_func_array($handler, $callback_params);
}
}
}
return $special_field_data;
}
示例12: testAfterValidate
/**
* Test Before Validate - Unflatten Special Fields Data
*
* @author Everton Yoshitani <everton@wizehive.com>
* @since 1.0
* @return void
*/
public function testAfterValidate()
{
$data = array('id' => 1, 'options.type' => 1, 'options.frequency' => '2 mins');
$this->SpecialFieldsModel->data = array($this->SpecialFieldsModel->alias => $data);
$this->SpecialFieldsBehavior = $this->getMock('SpecialFieldsBehavior', array('getValidationFieldNames'));
$validation_field_names = array('options');
$this->SpecialFieldsBehavior->expects($this->once())->method('getValidationFieldNames')->with($this->SpecialFieldsModel)->will($this->returnValue($validation_field_names));
$this->SpecialFieldsBehavior->afterValidate($this->SpecialFieldsModel);
$expected = Hash::expand($data);
$this->assertEquals($expected, $this->SpecialFieldsModel->data[$this->SpecialFieldsModel->alias]);
}
示例13: initFiles
private function initFiles()
{
$files = [];
foreach (['js', 'css'] as $script) {
foreach (['files', 'inline'] as $type) {
$key = sprintf('%s.%s', $script, $type);
$files[$key] = [];
}
}
$this->files = Hash::expand($files);
}
示例14: __setupViewParameters
/**
* __setupViewParameters method
*
* @param array $registration 登録フォームデータ
* @param string $backUrl BACKボタン押下時の戻るパス
* @return void
*/
private function __setupViewParameters($registration, $backUrl)
{
//$isPublished = $this->Registration->hasPublished($registration);
// エラーメッセージはページ、項目、選択肢要素のそれぞれの場所に割り当てる
$this->NetCommons->handleValidationError($this->Registration->validationErrors);
$flatError = Hash::flatten($this->Registration->validationErrors);
$newFlatError = array();
foreach ($flatError as $key => $val) {
if (preg_match('/^(.*)\\.(.*)\\.(.*)$/', $key, $matches)) {
$newFlatError[$matches[1] . '.error_messages.' . $matches[2] . '.' . $matches[3]] = $val;
}
}
$registration = Hash::merge($registration, Hash::expand($newFlatError));
$registration = $this->NetCommonsTime->toUserDatetimeArray($registration, array('Registration.answer_start_period', 'Registration.answer_end_period', 'Registration.total_show_start_period'));
$this->set('postUrl', array('url' => $this->_getActionUrl($this->action)));
if ($this->layout == 'NetCommons.setting') {
$this->set('cancelUrl', array('url' => NetCommonsUrl::backToIndexUrl('default_setting_action')));
} else {
$this->set('cancelUrl', array('url' => NetCommonsUrl::backToPageUrl()));
}
$this->set('deleteUrl', array('url' => $this->_getActionUrl('delete')));
$this->set('questionTypeOptions', $this->Registrations->getQuestionTypeOptionsWithLabel());
$this->set('newPageLabel', __d('registrations', 'page'));
$this->set('newQuestionLabel', __d('registrations', 'New Question'));
$this->set('newChoiceLabel', __d('registrations', 'new choice'));
$this->set('newChoiceColumnLabel', __d('registrations', 'new column choice'));
$this->set('newChoiceOtherLabel', __d('registrations', 'other choice'));
// 都道府県データ
$prefectures = $this->_getPrefectures();
$this->set('prefectures', $prefectures);
//$this->set('isPublished', $isPublished);
$this->set('isPublished', false);
$this->request->data = $registration;
$this->request->data['Frame'] = Current::read('Frame');
$this->request->data['Block'] = Current::read('Block');
// メール通知設定
$conditions = ['plugin_key' => 'registrations', 'block_key' => Current::read('Block.key')];
$mailSetting = $this->MailSetting->find('first', ['conditions' => $conditions]);
$this->set('mailSetting', $mailSetting);
}
示例15: convertAttributesToFields
/**
* Convert attributes to fields
*
* @author Anthony Putignano <anthony@wizehive.com>
* @since 1.0
* @return object
*/
public function convertAttributesToFields()
{
if (empty($this->Controller->request->data) || !is_array($this->Controller->request->data)) {
return $this;
}
if (empty($this->_model)) {
return $this;
}
$model = $this->_model;
$this->forModel();
if (!isset($this->{$model})) {
$this->{$model} = ClassRegistry::init($model);
}
foreach ($this->Controller->request->data as $key => $model_group) {
foreach ($model_group as $current_model => $save_all_data) {
if (empty($this->{$model}->{$current_model}) || !is_object($this->{$model}->{$current_model})) {
$modelObject = $this->{$model};
} else {
$modelObject = $this->{$model}->{$current_model};
}
$field_map = $modelObject->getFieldMap($modelObject->attributes());
foreach ($save_all_data as $save_all_key => $data) {
$new_data = array();
foreach ($field_map as $field => $attribute) {
if (array_key_exists($attribute, $data)) {
$temp = Hash::expand(array($field => $data[$attribute]));
$new_data = Hash::merge($new_data, $temp);
}
}
$this->Controller->request->data[$key][$current_model][$save_all_key] = $new_data;
}
}
}
return $this;
}