当前位置: 首页>>代码示例>>PHP>>正文


PHP Hash::flatten方法代码示例

本文整理汇总了PHP中Cake\Utility\Hash::flatten方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::flatten方法的具体用法?PHP Hash::flatten怎么用?PHP Hash::flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Utility\Hash的用法示例。


在下文中一共展示了Hash::flatten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dump

 /**
  * {@inheritdoc}
  *
  * @param string $key The identifier to write to.
  * @param array $data The data to dump.
  * @return bool True on success or false on failure.
  */
 public function dump($key, array $data)
 {
     $data = Hash::flatten($data);
     array_walk($data, [$this, '_persist'], $key);
     array_filter($data);
     return (bool) $data;
 }
开发者ID:gourmet,项目名称:aroma,代码行数:14,代码来源:DbConfig.php

示例2: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Entity $entity Entity
  * @param int $code code to report to client
  */
 public function __construct(Entity $entity, $code = 422)
 {
     $this->_validationErrors = array_filter((array) $entity->errors());
     $flat = Hash::flatten($this->_validationErrors);
     $errorCount = $this->_validationErrorCount = count($flat);
     $this->message = __dn('crud', 'A validation error occurred', '{0} validation errors occurred', $errorCount, [$errorCount]);
     parent::__construct($this->message, $code);
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:14,代码来源:ValidationException.php

示例3: postLink

 /**
  * @inheritdoc
  */
 public function postLink($title, $url = null, array $options = [])
 {
     $options += ['block' => null, 'confirm' => null];
     $requestMethod = 'POST';
     if (!empty($options['method'])) {
         $requestMethod = strtoupper($options['method']);
         unset($options['method']);
     }
     $confirmMessage = $options['confirm'];
     unset($options['confirm']);
     $formName = str_replace('.', '', uniqid('post_', true));
     $formOptions = ['name' => $formName, 'class' => 'csp-hidden', 'method' => 'post'];
     if (isset($options['target'])) {
         $formOptions['target'] = $options['target'];
         unset($options['target']);
     }
     $templater = $this->templater();
     $this->_lastAction($url);
     $action = $templater->formatAttributes(['action' => $this->Url->build($url), 'escape' => false]);
     $out = $templater->format('formStart', ['attrs' => $templater->formatAttributes($formOptions) . $action]);
     $out .= $this->hidden('_method', ['value' => $requestMethod]);
     $out .= $this->_csrfField();
     $fields = [];
     if (isset($options['data']) && is_array($options['data'])) {
         foreach (Hash::flatten($options['data']) as $key => $value) {
             $fields[$key] = $value;
             $out .= $this->hidden($key, ['value' => $value]);
         }
         unset($options['data']);
     }
     $out .= $this->secure($fields);
     $out .= $templater->format('formEnd', []);
     if ($options['block']) {
         if ($options['block'] === true) {
             $options['block'] = __FUNCTION__;
         }
         $this->_View->append($options['block'], $out);
         $out = '';
     }
     unset($options['block']);
     $url = '#';
     if (!empty($options['class'])) {
         $options['class'] .= ' csp-' . __FUNCTION__;
     } else {
         $options['class'] = 'csp-' . __FUNCTION__;
     }
     $options['data-csp-form'] = $formName;
     if ($confirmMessage) {
         if (isset($options['escape']) && $options['escape'] === false) {
             $confirmMessage = h($confirmMessage);
         }
         $options['data-csp-confirm'] = $confirmMessage;
     }
     $out .= $this->Html->link($title, $url, $options);
     return $out;
 }
开发者ID:thefredfox,项目名称:cakephp-csp,代码行数:59,代码来源:FormHelperTrait.php

示例4: _addTokens

 /**
  * Add the CSRF and Security Component tokens if necessary.
  *
  * @param string $url
  * @param array $data
  * @return array
  */
 protected function _addTokens($url, $data)
 {
     if ($this->_securityToken === true) {
         $_data = $this->_unsetUnlockedData($data);
         $keys = array_map(function ($field) {
             return preg_replace('/(\\.\\d+)+$/', '', $field);
         }, array_keys(Hash::flatten($_data)));
         $tokenData = $this->_buildFieldToken($url, array_unique($keys));
         $data['_Token'] = $tokenData;
         $data['_Token']['debug'] = 'SecurityComponent debug data would be added here';
     }
     $data = $this->_setCsrfToken($data);
     return $data;
 }
开发者ID:UnionCMS,项目名称:Core,代码行数:21,代码来源:IntegrationCase.php

示例5: getFlatArray

 /**
  * @param EntityInterface $entity
  * @return array
  */
 public function getFlatArray(EntityInterface $entity)
 {
     $array = $this->getArray($entity, true);
     $flattened = Hash::flatten($array);
     $keys = array_keys($flattened);
     $values = array_values($flattened);
     foreach ($keys as &$key) {
         if (preg_match('/^\\w+\\.(\\d+)\\.(\\w+)$/', $key, $matches)) {
             $key = sprintf('%s[%s]', $matches[2], $matches[1]);
         }
     }
     unset($key);
     $formatted = array_combine($keys, $values);
     return $formatted;
 }
开发者ID:quartetcom,项目名称:base-api-php-client,代码行数:19,代码来源:EntityManager.php

示例6: _addTokens

 /**
  * Add the CSRF and Security Component tokens if necessary.
  *
  * @param string $url The URL the form is being submitted on.
  * @param array $data The request body data.
  * @return array The request body with tokens added.
  */
 protected function _addTokens($url, $data)
 {
     if ($this->_securityToken === true) {
         $keys = array_map(function ($field) {
             return preg_replace('/(\\.\\d+)+$/', '', $field);
         }, array_keys(Hash::flatten($data)));
         $tokenData = $this->_buildFieldToken($url, array_unique($keys));
         $data['_Token'] = $tokenData;
         $data['_Token']['debug'] = 'SecurityComponent debug data would be added here';
     }
     if ($this->_csrfToken === true) {
         if (!isset($this->_cookie['csrfToken'])) {
             $this->_cookie['csrfToken'] = Text::uuid();
         }
         if (!isset($data['_csrfToken'])) {
             $data['_csrfToken'] = $this->_cookie['csrfToken'];
         }
     }
     return $data;
 }
开发者ID:aceat64,项目名称:cakephp,代码行数:27,代码来源:IntegrationTestCase.php

示例7: _addTokens

 /**
  * Add the CSRF and Security Component tokens if necessary.
  *
  * @param string $url The URL the form is being submitted on.
  * @param array $data The request body data.
  * @return array The request body with tokens added.
  */
 protected function _addTokens($url, $data)
 {
     if ($this->_securityToken === true) {
         $keys = Hash::flatten($data);
         $tokenData = $this->_buildFieldToken($url, $keys);
         $data['_Token'] = $tokenData;
     }
     if ($this->_csrfToken === true) {
         $csrfToken = Text::uuid();
         if (!isset($data['_csrfToken'])) {
             $data['_csrfToken'] = $csrfToken;
         }
         if (!isset($this->_cookie['csrfToken'])) {
             $this->_cookie['csrfToken'] = $csrfToken;
         }
     }
     return $data;
 }
开发者ID:HarkiratGhotra,项目名称:cake,代码行数:25,代码来源:IntegrationTestCase.php

示例8: summary

 /**
  * Get the number of files included in this request.
  *
  * @return string
  */
 public function summary()
 {
     $data = $this->_data;
     if (empty($data)) {
         $data = $this->_prepare();
     }
     return count(Hash::flatten($data));
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:13,代码来源:IncludePanel.php

示例9: commands

 /**
  * Return a list of all commands
  *
  * @return array
  */
 public function commands()
 {
     $shellList = $this->getShellList();
     $flatten = Hash::flatten($shellList);
     $duplicates = array_intersect($flatten, array_unique(array_diff_key($flatten, array_unique($flatten))));
     $duplicates = Hash::expand($duplicates);
     $options = [];
     foreach ($shellList as $type => $commands) {
         foreach ($commands as $shell) {
             $prefix = '';
             if (!in_array(strtolower($type), ['app', 'core']) && isset($duplicates[$type]) && in_array($shell, $duplicates[$type])) {
                 $prefix = $type . '.';
             }
             $options[] = $prefix . $shell;
         }
     }
     return $options;
 }
开发者ID:tgr0ss,项目名称:cakephp,代码行数:23,代码来源:CommandTask.php

示例10: buildUrl

 public function buildUrl($item, $request)
 {
     $url = $item['url'];
     $params = Hash::flatten($request);
     $result = [];
     if (is_array($url)) {
         foreach ($url as $key => $value) {
             if (is_string($value)) {
                 if (!is_int($key)) {
                     $result[$key] = Text::insert($value, $params);
                 } else {
                     $result[] = Text::insert($value, $params);
                 }
             } else {
                 $result[$key] = $value;
             }
         }
     } else {
         $result = Text::insert($url, $params);
     }
     return Router::url($result);
 }
开发者ID:cakemanager,项目名称:cakeadmin-adminbar,代码行数:22,代码来源:AdminBarComponent.php

示例11: postLink

 /**
  * Creates an HTML link, but access the URL using the method you specify
  * (defaults to POST). Requires javascript to be enabled in browser.
  *
  * This method creates a `<form>` element. If you want to use this method inside of an
  * existing form, you must use the `block` option so that the new form is being set to
  * a view block that can be rendered outside of the main form.
  *
  * If all you are looking for is a button to submit your form, then you should use
  * `FormHelper::button()` or `FormHelper::submit()` instead.
  *
  * ### Options:
  *
  * - `data` - Array with key/value to pass in input hidden
  * - `method` - Request method to use. Set to 'delete' to simulate
  *   HTTP/1.1 DELETE request. Defaults to 'post'.
  * - `confirm` - Confirm message to show.
  * - `block` - Set to true to append form to view block "postLink" or provide
  *   custom block name.
  * - Other options are the same of HtmlHelper::link() method.
  * - The option `onclick` will be replaced.
  *
  * @param string $title The content to be wrapped by <a> tags.
  * @param string|array|null $url Cake-relative URL or array of URL parameters, or
  *   external URL (starts with http://)
  * @param array $options Array of HTML attributes.
  * @return string An `<a />` element.
  * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-standalone-buttons-and-post-links
  */
 public function postLink($title, $url = null, array $options = [])
 {
     $options += ['block' => null, 'confirm' => null];
     $requestMethod = 'POST';
     if (!empty($options['method'])) {
         $requestMethod = strtoupper($options['method']);
         unset($options['method']);
     }
     $confirmMessage = $options['confirm'];
     unset($options['confirm']);
     $formName = str_replace('.', '', uniqid('post_', true));
     $formOptions = ['name' => $formName, 'style' => 'display:none;', 'method' => 'post'];
     if (isset($options['target'])) {
         $formOptions['target'] = $options['target'];
         unset($options['target']);
     }
     $templater = $this->templater();
     $restoreAction = $this->_lastAction;
     $this->_lastAction($url);
     $action = $templater->formatAttributes(['action' => $this->Url->build($url), 'escape' => false]);
     $out = $this->formatTemplate('formStart', ['attrs' => $templater->formatAttributes($formOptions) . $action]);
     $out .= $this->hidden('_method', ['value' => $requestMethod, 'secure' => static::SECURE_SKIP]);
     $out .= $this->_csrfField();
     $fields = [];
     if (isset($options['data']) && is_array($options['data'])) {
         foreach (Hash::flatten($options['data']) as $key => $value) {
             $fields[$key] = $value;
             $out .= $this->hidden($key, ['value' => $value, 'secure' => static::SECURE_SKIP]);
         }
         unset($options['data']);
     }
     $out .= $this->secure($fields);
     $out .= $this->formatTemplate('formEnd', []);
     $this->_lastAction = $restoreAction;
     if ($options['block']) {
         if ($options['block'] === true) {
             $options['block'] = __FUNCTION__;
         }
         $this->_View->append($options['block'], $out);
         $out = '';
     }
     unset($options['block']);
     $url = '#';
     $onClick = 'document.' . $formName . '.submit();';
     if ($confirmMessage) {
         $options['onclick'] = $this->_confirm($confirmMessage, $onClick, '', $options);
     } else {
         $options['onclick'] = $onClick . ' ';
     }
     $options['onclick'] .= 'event.returnValue = false; return false;';
     $out .= $this->Html->link($title, $url, $options);
     return $out;
 }
开发者ID:tgr0ss,项目名称:cakephp,代码行数:82,代码来源:FormHelper.php

示例12: formatParams

 /**
  * Returns the extracted parameters from a parameters string.
  *
  * @param string $params The parameters string
  * @return array
  */
 protected function formatParams($params)
 {
     //Clean parameters
     $params = preg_replace('/(\'[^\']+\')::[^ ,\\]]+/', '\\1', $params);
     if (preg_match('/^ARRAY\\[(.*)\\]$/', $params, $arrayParams)) {
         $params = [preg_split('/, /', $arrayParams[1], null, PREG_SPLIT_NO_EMPTY)];
     } else {
         $params = preg_split('/, /', $params, null, PREG_SPLIT_NO_EMPTY);
     }
     //Trim quotes around values
     foreach (Hash::flatten($params) as $path => $value) {
         $params = Hash::insert($params, $path, preg_replace('/^\'(.*)\'$/', '\\1', $value));
     }
     return $params;
 }
开发者ID:jmjjg,项目名称:cakephp-postgres,代码行数:21,代码来源:AutovalidateBehavior.php

示例13: addRole

 /**
  * adds a new ARO to the tree
  *
  * @param array $aro one or more ARO records
  * @return void
  */
 public function addRole(array $aro)
 {
     foreach ($aro as $role => $inheritedRoles) {
         if (!isset($this->_tree[$role])) {
             $this->_tree[$role] = array();
         }
         if (!empty($inheritedRoles)) {
             if (is_string($inheritedRoles)) {
                 $inheritedRoles = array_map('trim', explode(',', $inheritedRoles));
             }
             foreach ($inheritedRoles as $dependency) {
                 // detect cycles
                 $roles = $this->roles($dependency);
                 if (in_array($role, Hash::flatten($roles))) {
                     $path = '';
                     foreach ($roles as $roleDependencies) {
                         $path .= implode('|', (array) $roleDependencies) . ' -> ';
                     }
                     trigger_error(sprintf('cycle detected when inheriting %s from %s. Path: %s', $role, $dependency, $path . $role));
                     continue;
                 }
                 if (!isset($this->_tree[$dependency])) {
                     $this->_tree[$dependency] = array();
                 }
                 $this->_tree[$dependency][] = $role;
             }
         }
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:35,代码来源:PhpAcl.php

示例14: southFour

 public function southFour()
 {
     // Init table
     $resultsTable = TableRegistry::get('Results');
     // Prepare
     $year1 = Hash::get($this->request->query, 'search_year1');
     $month1 = Hash::get($this->request->query, 'search_month1');
     $year2 = Hash::get($this->request->query, 'search_year2');
     $month2 = Hash::get($this->request->query, 'search_month2');
     $head = Hash::get($this->request->query, 'search_head');
     $trail = Hash::get($this->request->query, 'search_trail');
     $startFormat = "";
     $endFormat = "";
     $startFormatValue = "";
     $endFormatValue = "";
     $conditions = ['area' => Configure::read('Area.south.code'), 'level IN' => [1, 9]];
     // Setting get data by year, month
     if (Validation::notBlank($year1)) {
         $startFormat .= '%Y';
         $startFormatValue .= $year1;
     }
     if (Validation::notBlank($month1)) {
         $startFormat .= '%m';
         $startFormatValue .= $month1;
     }
     if (Validation::notBlank($year2)) {
         $endFormat .= '%Y';
         $endFormatValue .= $year2;
     }
     if (Validation::notBlank($month2)) {
         $endFormat .= '%m';
         $endFormatValue .= $month2;
     }
     if ($startFormat) {
         $conditions[] = "DATE_FORMAT(date_result, '{$startFormat}') >= {$startFormatValue}";
     }
     if ($endFormat) {
         $conditions[] = "DATE_FORMAT(date_result, '{$endFormat}') <= {$endFormatValue}";
     }
     // Setting get data by head, trail
     if (Validation::notBlank($head)) {
         $conditions[] = "MID(content, -2, 1) = {$head}";
     }
     if (Validation::notBlank($trail)) {
         $conditions[] = "MID(content, -1) = {$trail}";
     }
     $query = $resultsTable->find('all');
     $trailTwo = $query->func()->mid(['content' => 'literal', '-2']);
     $query->select(['id', 'date_result', 'trail' => $trailTwo, 'city', 'level'])->where($conditions)->order(['date_result' => 'DESC', 'city' => 'ASC', 'level' => 'DESC']);
     // process space
     $htmlSpace = [];
     $htmlSpaceHead = [];
     if (Validation::notBlank($head)) {
         $sorted = $query->sortBy(function ($trail) {
             return $trail->date_result->i18nFormat('yyyyMMdd');
         }, SORT_ASC);
         foreach ($sorted as $key => $value) {
             $date = new \DateTime($value->date_result->i18nFormat('yyyy-MM-dd'));
             $line = in_array($value->city, Configure::read('COMMAND.CHANNEL.line1')) ? 1 : 2;
             $line = $line . "_" . ($value->level == 9 ? 1 : 2);
             $prevDate = isset($htmlSpace[$line]) ? $htmlSpace[$line]['prev_date'] : $date;
             $space = $prevDate->diff($date)->format("%a");
             // Check is space greater two month
             $spaceMonth = $date->format('Ym') - $prevDate->format('Ym');
             if ($space > 30 && $spaceMonth != 1 && $spaceMonth != 89) {
                 continue;
             }
             if ($prevDate->format('Y-m-d') != $date->format('Y-m-d')) {
                 $htmlSpace[$line][$space][] = $prevDate->format('Y-m-d') . " - " . $date->format('Y-m-d');
                 $htmlSpace[$line]["{$space}_count"] = count($htmlSpace[$line][$space]);
             }
             $htmlSpace[$line]['prev_date'] = $date;
             krsort($htmlSpace[$line]);
             if (!in_array($space, $htmlSpaceHead)) {
                 $htmlSpaceHead[] = $space;
             }
         }
         ksort($htmlSpace);
         rsort($htmlSpaceHead);
         $htmlSpace = Hash::flatten($htmlSpace);
         //var_dump($htmlSpaceHead);
         //var_dump($htmlSpace);exit;
     }
     $this->set('trails', $query);
     $this->set('htmlSpace', $htmlSpace);
     $this->set('htmlSpaceHead', $htmlSpaceHead);
 }
开发者ID:philliptan,项目名称:lode,代码行数:87,代码来源:PagesController.php

示例15: _extractEntityWords

 /**
  * Extracts a list of words to by indexed for given entity.
  *
  * NOTE: Words can be repeated, this allows to search phrases.
  *
  * @param \Cake\Datasource\EntityInterface $entity The entity for which generate
  *  the list of words
  * @return string Space-separated list of words. e.g. `cat dog this that`
  */
 protected function _extractEntityWords(EntityInterface $entity)
 {
     $text = '';
     $entityArray = $entity->toArray();
     $entityArray = Hash::flatten($entityArray);
     foreach ($entityArray as $key => $value) {
         if (is_string($value) || is_numeric($value)) {
             $text .= " {$value}";
         }
     }
     $text = str_replace(["\n", "\r"], '', trim((string) $text));
     // remove new lines
     $text = strip_tags($text);
     // remove HTML tags, but keep their content
     $strict = $this->config('strict');
     if (!empty($strict)) {
         // only: space, digits (0-9), letters (any language), ".", ",", "-", "_", "/", "\"
         $pattern = is_string($strict) ? $strict : '[^\\p{L}\\p{N}\\s\\@\\.\\,\\-\\_\\/\\0-9]';
         $text = preg_replace('/' . $pattern . '/ui', ' ', $text);
     }
     $text = trim(preg_replace('/\\s{2,}/i', ' ', $text));
     // remove double spaces
     $text = mb_strtolower($text);
     // all to lowercase
     $text = $this->_filterText($text);
     // filter
     $text = iconv('UTF-8', 'UTF-8//IGNORE', mb_convert_encoding($text, 'UTF-8'));
     // remove any invalid character
     return trim($text);
 }
开发者ID:quickapps-plugins,项目名称:search,代码行数:39,代码来源:GenericEngine.php


注:本文中的Cake\Utility\Hash::flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。