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


PHP Set::expand方法代码示例

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


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

示例1: _recursiveFilter

 /**
  * @param $filter
  * @param $value
  * @param $element
  * @param string $path
  * @return array|mixed
  */
 protected function _recursiveFilter($filter, $value, $element, $path = '')
 {
     if (is_array($value)) {
         $cleanValues = array();
         $parent = $path;
         foreach ($value as $k => $v) {
             $path = $parent !== '' ? $parent . '.' . $k : $k;
             $cleanValues[$k] = $this->_recursiveFilter($filter, $v, $element, $path);
         }
         return $cleanValues;
     } else {
         if ($element === '__ALL__' || $element === $path || Set::matches($element, Set::expand(array($path => '')))) {
             return call_user_func($filter, $value);
         } else {
             return $value;
         }
     }
 }
开发者ID:tsmsogn,项目名称:datafilter,代码行数:25,代码来源:DatafilterComponent.php

示例2: testExpand

 /**
  * Tests Set::expand
  *
  * @return void
  */
 public function testExpand()
 {
     $data = array('My', 'Array', 'To', 'Flatten');
     $flat = Set::flatten($data);
     $result = Set::expand($flat);
     $this->assertEquals($data, $result);
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:12,代码来源:SetTest.php

示例3: read

 /**
  * Reads records from a database using a `lithium\data\model\Query` object or raw SQL string.
  *
  * @param string|object $query   `lithium\data\model\Query` object or SQL string.
  * @param array         $options If `$query` is a raw string, contains the values that will be escaped
  *                               and quoted. Other options:
  *                               - `'return'` _string_: switch return between `'array'`, `'item'`, or
  *                               `'resource'` _string_: Defaults to `'item'`.
  *
  * @return mixed Determined by `$options['return']`.
  * @filter
  */
 public function read($query, array $options = [])
 {
     $defaults = ['return' => is_string($query) ? 'array' : 'item', 'schema' => null, 'quotes' => $this->_quotes];
     $options += $defaults;
     return $this->_filter(__METHOD__, compact('query', 'options'), function ($self, $params) {
         $query = $params['query'];
         $args = $params['options'];
         $return = $args['return'];
         unset($args['return']);
         $model = is_object($query) ? $query->model() : null;
         if (is_string($query)) {
             $sql = String::insert($query, $self->value($args));
         } else {
             if (!($data = $self->invokeMethod('_queryExport', [$query]))) {
                 return false;
             }
             $sql = $self->renderCommand($data['type'], $data);
         }
         $result = $self->invokeMethod('_execute', [$sql]);
         switch ($return) {
             case 'resource':
                 return $result;
             case 'array':
                 $columns = $args['schema'] ?: $self->schema($query, $result);
                 if (!is_array(reset($columns))) {
                     $columns = ['' => $columns];
                 }
                 $i = 0;
                 $records = [];
                 foreach ($result as $data) {
                     $offset = 0;
                     $records[$i] = [];
                     foreach ($columns as $path => $cols) {
                         $len = count($cols);
                         $values = array_combine($cols, array_slice($data, $offset, $len));
                         if ($path) {
                             $records[$i][$path] = $values;
                         } else {
                             $records[$i] += $values;
                         }
                         $offset += $len;
                     }
                     $i++;
                 }
                 return Set::expand($records);
             case 'item':
                 return $model::create([], compact('query', 'result') + ['class' => 'set', 'defaults' => false]);
         }
     });
 }
开发者ID:kaibosh,项目名称:nZEDb,代码行数:62,代码来源:Database.php

示例4: create

 /**
  * Instantiates a new record or document object, initialized with any data passed in. For
  * example:
  *
  * {{{
  * $post = Posts::create(array('title' => 'New post'));
  * echo $post->title; // echoes 'New post'
  * $success = $post->save();
  * }}}
  *
  * Note that while this method creates a new object, there is no effect on the database until
  * the `save()` method is called.
  *
  * In addition, this method can be used to simulate loading a pre-existing object from the
  * database, without actually querying the database:
  *
  * {{{
  * $post = Posts::create(array('id' => $id, 'moreData' => 'foo'), array('exists' => true));
  * $post->title = 'New title';
  * $success = $post->save();
  * }}}
  *
  * This will create an update query against the object with an ID matching `$id`. Also note that
  * only the `title` field will be updated.
  *
  * @param array $data    Any data that this object should be populated with initially.
  * @param array $options Options to be passed to item.
  *
  * @return object Returns a new, _un-saved_ record or document object. In addition to the values
  *         passed to `$data`, the object will also contain any values assigned to the
  *         `'default'` key of each field defined in `$_schema`.
  * @filter
  */
 public static function create(array $data = [], array $options = [])
 {
     $defaults = ['defaults' => true, 'class' => 'entity'];
     $options += $defaults;
     return static::_filter(__FUNCTION__, compact('data', 'options'), function ($self, $params) {
         $class = $params['options']['class'];
         unset($params['options']['class']);
         if ($class === 'entity' && $params['options']['defaults']) {
             $data = Set::merge(Set::expand($self::schema()->defaults()), $params['data']);
         } else {
             $data = $params['data'];
         }
         $options = ['model' => $self, 'data' => $data] + $params['options'];
         return $self::invokeMethod('_instance', [$class, $options]);
     });
 }
开发者ID:kaibosh,项目名称:nZEDb,代码行数:49,代码来源:Model.php


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