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


PHP Set::slice方法代码示例

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


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

示例1: run

 public function run($id = null)
 {
     $id = !is_null($id) ? $id : $this->request->id;
     $model = $this->scaffold['model'];
     $object = $model::first($id);
     if (!$object) {
         $url = array('action' => 'index');
         return $this->redirect($url);
     }
     list($temp, $options) = Set::slice($this->request->data, array('validate', 'strict'));
     switch ($this->request->data['mode']) {
         case 'keep':
             $options['overwrite'] = false;
             break;
         case 'remove':
             $options['prune'] = true;
             break;
     }
     $result = $object->run($options);
     $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()}));
     return $this->redirect($url);
 }
开发者ID:bruensicke,项目名称:radium,代码行数:22,代码来源:AssetsController.php

示例2: export

 /**
  * Convert the query's properties to the data sources' syntax and return it as an array.
  *
  * @param \lithium\data\Source $source Instance of the data source to use for conversion.
  * @param array $options Options to use when exporting the data.
  * @return array Returns an array containing a data source-specific representation of a query.
  */
 public function export(Source $source, array $options = array())
 {
     $defaults = array('keys' => array());
     $options += $defaults;
     if ($options['keys']) {
         $keys = array_flip($options['keys']);
     } else {
         $keys =& $this->_config;
     }
     list($copy, $apply) = Set::slice($keys, $source->methods());
     if (isset($keys['with'])) {
         $this->applyStrategy($source);
     }
     foreach ($apply as $item => $value) {
         $results[$item] = $source->{$item}($this->{$item}(), $this);
     }
     foreach ($copy as $item => $value) {
         $results[$item] = $this->_config[$item];
     }
     if (array_key_exists('data', $keys)) {
         $results['data'] = $this->_exportData();
     }
     if (array_key_exists('source', $keys)) {
         $results['source'] = $source->name($results['source']);
     }
     if (!isset($results['fields'])) {
         return $results;
     }
     $created = array('fields', 'values');
     if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
         $results = $results['fields'] + $results;
     }
     return $results;
 }
开发者ID:fedeisas,项目名称:lithium,代码行数:41,代码来源:Query.php

示例3: testSetSlice

 public function testSetSlice()
 {
     $data = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
     list($kept, $removed) = Set::slice($data, array('key3'));
     $this->assertEqual(array('key3' => 'val3'), $removed);
     $this->assertEqual(array('key1' => 'val1', 'key2' => 'val2'), $kept);
     $data = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
     list($kept, $removed) = Set::slice($data, array('key1', 'key3'));
     $this->assertEqual(array('key1' => 'val1', 'key3' => 'val3'), $removed);
     $this->assertEqual(array('key2' => 'val2'), $kept);
     $data = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3');
     list($kept, $removed) = Set::slice($data, 'key2');
     $this->assertEqual(array('key2' => 'val2'), $removed);
     $this->assertEqual(array('key1' => 'val1', 'key3' => 'val3'), $kept);
     $data = array('key1' => 'val1', 'key2' => 'val2', 'key3' => array('foo' => 'bar'));
     list($kept, $removed) = Set::slice($data, array('key1', 'key3'));
     $this->assertEqual(array('key1' => 'val1', 'key3' => array('foo' => 'bar')), $removed);
     $this->assertEqual(array('key2' => 'val2'), $kept);
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:19,代码来源:SetTest.php

示例4: _init

 /**
  * Initializer. Initializes properties like `Database::$_strategies` because
  * closures cannot be created within the class definition.
  *
  * @see lithium\data\source\Database::$_columns
  * @see lithium\data\source\Database::$_strings
  * @see lithium\data\source\Database::$_strategies
  */
 protected function _init()
 {
     parent::_init();
     $formatters = $this->_formatters();
     foreach ($this->_columns as $type => $column) {
         if (isset($formatters[$type])) {
             $this->_columns[$type]['formatter'] = $formatters[$type];
         }
     }
     $this->_strings += array('read' => 'SELECT {:fields} FROM {:source} {:alias} {:joins} {:conditions} {:group} ' . '{:having} {:order} {:limit};{:comment}');
     $this->_strategies += array('joined' => function ($self, $model, $context) {
         $with = $context->with();
         $strategy = function ($me, $model, $tree, $path, $from, &$deps) use($self, $context, $with) {
             foreach ($tree as $name => $childs) {
                 if (!($rel = $model::relations($name))) {
                     throw new QueryException("Model relationship `{$name}` not found.");
                 }
                 $constraints = array();
                 $alias = $name;
                 $relPath = $path ? $path . '.' . $name : $name;
                 if (isset($with[$relPath])) {
                     list($unallowed, $allowed) = Set::slice($with[$relPath], array('alias', 'constraints'));
                     if ($unallowed) {
                         $message = "Only `'alias'` and `'constraints'` are allowed in ";
                         $message .= "`'with'` using the `'joined'` strategy.";
                         throw new QueryException($message);
                     }
                     extract($with[$relPath]);
                 }
                 $to = $context->alias($alias, $relPath);
                 $deps[$to] = $deps[$from];
                 $deps[$to][] = $from;
                 if ($context->relationships($relPath) === null) {
                     $context->relationships($relPath, array('type' => $rel->type(), 'model' => $rel->to(), 'fieldName' => $rel->fieldName(), 'alias' => $to));
                     $self->join($context, $rel, $from, $to, $constraints);
                 }
                 if (!empty($childs)) {
                     $me($me, $rel->to(), $childs, $relPath, $to, $deps);
                 }
             }
         };
         $tree = Set::expand(array_fill_keys(array_keys($with), false));
         $alias = $context->alias();
         $deps = array($alias => array());
         $strategy($strategy, $model, $tree, '', $alias, $deps);
         $models = $context->models();
         foreach ($context->fields() as $field) {
             if (!is_string($field)) {
                 continue;
             }
             list($alias, $field) = $self->invokeMethod('_splitFieldname', array($field));
             $alias = $alias ?: $field;
             if ($alias && isset($models[$alias])) {
                 foreach ($deps[$alias] as $depAlias) {
                     $depModel = $models[$depAlias];
                     $context->fields(array($depAlias => (array) $depModel::meta('key')));
                 }
             }
         }
     }, 'nested' => function ($self, $model, $context) {
         throw new QueryException("This strategy is not yet implemented.");
     });
 }
开发者ID:shopblocks,项目名称:lithium,代码行数:71,代码来源:Database.php

示例5: import

 /**
  * imports data attribute into database. Allows importing of all model data within one file.
  * Will call a method on each model, named `bulkImport` (can be customized) to do the heavy
  * lifting of import. Thus, it allows overwriting the import on a per-model basis.
  *
  * The data of the asset, to be decoded must have the following structure:
  *
  *	Array (
  *		'radium\\models\\Contents' => Array (
  *			'5328587a4eaa3af84e000000' => Array (
  *				'key' => 'value'   // all data per model
  *			),
  *			'5428587a4eaa3af84e000001' => Array (
  *				'key' => 'value'   // all data per model
  *			),
  *		),
  *
  * @see radium\data\BaseModel::bulkImport()
  * @param object $asset instance of current record
  * @param array $options additional options, will be passed into bulkImport method.
  *        - `function`: pass in a callback to handle the import of each record on the
  *                      corresponding model class, defaults to `bulkImport`.
  * @return array parsed content of Assets bytes
  */
 public function import($asset, array $options = array())
 {
     $defaults = array('function' => 'bulkImport');
     $options += $defaults;
     $data = $asset->decode();
     $result = array();
     list($temp, $params) = Set::slice($options, array('dry', 'prune', 'overwrite', 'strict'));
     $models = array_keys($data);
     foreach ($models as $model) {
         $items =& $data[$model];
         $result[$model] = call_user_func(array($model, $options['function']), $items, $params);
     }
     return $result;
 }
开发者ID:bruensicke,项目名称:radium,代码行数:38,代码来源:Assets.php

示例6: __construct

 /**
  * Creates the database object and set default values for it.
  *
  * Options defined:
  *  - 'database' _string_ Name of the database to use. Defaults to `null`.
  *  - 'host' _string_ Name/address of server to connect to. Defaults to 'localhost'.
  *  - 'login' _string_ Username to use when connecting to server. Defaults to 'root'.
  *  - 'password' _string_ Password to use when connecting to server. Defaults to `''`.
  *  - 'persistent' _boolean_ If true a persistent connection will be attempted, provided the
  *    adapter supports it. Defaults to `true`.
  *
  * @param $config array Array of configuration options.
  * @return Database object.
  */
 public function __construct(array $config = array())
 {
     $defaults = array('persistent' => true, 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => null, 'encoding' => null, 'dsn' => null, 'options' => array());
     $this->_strings += array('read' => 'SELECT {:fields} FROM {:source} {:alias} {:joins} {:conditions} {:group} ' . '{:having} {:order} {:limit};{:comment}');
     $this->_strategies += array('joined' => function ($self, $model, $context) {
         $with = $context->with();
         $strategy = function ($me, $model, $tree, $path, $from, &$deps) use($self, $context, $with) {
             foreach ($tree as $name => $childs) {
                 if (!($rel = $model::relations($name))) {
                     throw new QueryException("Model relationship `{$name}` not found.");
                 }
                 $constraints = array();
                 $alias = $name;
                 $relPath = $path ? $path . '.' . $name : $name;
                 if (isset($with[$relPath])) {
                     list($unallowed, $allowed) = Set::slice($with[$relPath], array('alias', 'constraints'));
                     if ($unallowed) {
                         $message = "Only `'alias'` and `'constraints'` are allowed in ";
                         $message .= "`'with'` using the `'joined'` strategy.";
                         throw new QueryException($message);
                     }
                     extract($with[$relPath]);
                 }
                 $to = $context->alias($alias, $relPath);
                 $deps[$to] = $deps[$from];
                 $deps[$to][] = $from;
                 if ($context->relationships($relPath) === null) {
                     $context->relationships($relPath, array('type' => $rel->type(), 'model' => $rel->to(), 'fieldName' => $rel->fieldName(), 'alias' => $to));
                     $self->join($context, $rel, $from, $to, $constraints);
                 }
                 if (!empty($childs)) {
                     $me($me, $rel->to(), $childs, $relPath, $to, $deps);
                 }
             }
         };
         $tree = Set::expand(Set::normalize(array_keys($with)));
         $alias = $context->alias();
         $deps = array($alias => array());
         $strategy($strategy, $model, $tree, '', $alias, $deps);
         $models = $context->models();
         foreach ($context->fields() as $field) {
             list($alias, $field) = $self->invokeMethod('_splitFieldname', array($field));
             $alias = $alias ?: $field;
             if ($alias && isset($models[$alias])) {
                 foreach ($deps[$alias] as $depAlias) {
                     $depModel = $models[$depAlias];
                     $context->fields(array($depAlias => (array) $depModel::meta('key')));
                 }
             }
         }
     }, 'nested' => function ($self, $model, $context) {
         throw new QueryException("This strategy is not yet implemented.");
     });
     parent::__construct($config + $defaults);
 }
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:69,代码来源:Database.php


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