本文整理汇总了PHP中Cake\Collection\Collection::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::__construct方法的具体用法?PHP Collection::__construct怎么用?PHP Collection::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Collection\Collection
的用法示例。
在下文中一共展示了Collection::__construct方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructs a new collection that will dynamically add properties to it out of
* the values found in $values.
*
* @param array|\Traversable $into The target collection to which the values will
* be inserted at the specified path.
* @param string $path A dot separated list of properties that need to be traversed
* to insert the value into the target collection.
* @param array|\Traversable $values The source collection from which the values will
* be inserted at the specified path.
*/
public function __construct($into, $path, $values)
{
parent::__construct($into);
if (!$values instanceof Collection) {
$values = new Collection($values);
}
$path = explode('.', $path);
$target = array_pop($path);
$this->_path = $path;
$this->_target = $target;
$this->_values = $values;
}
示例2: __construct
/**
* Wraps this iterator around the passed items so when iterated they are returned
* in order.
*
* The callback will receive as first argument each of the elements in $items,
* the value returned in the callback will be used as the value for sorting such
* element. Please not that the callback function could be called more than once
* per element.
*
* @param array|\Traversable $items The values to sort
* @param callable|string $callback A function used to return the actual value to
* be compared. It can also be a string representing the path to use to fetch a
* column or property in each element
* @param int $dir either SORT_DESC or SORT_ASC
* @param int $type the type of comparison to perform, either SORT_STRING
* SORT_NUMERIC or SORT_NATURAL
*/
public function __construct($items, $callback, $dir = SORT_DESC, $type = SORT_NUMERIC)
{
if (is_array($items)) {
$items = new Collection($items);
}
$items = iterator_to_array($items, false);
$callback = $this->_propertyExtractor($callback);
$results = [];
foreach ($items as $key => $value) {
$results[$key] = $callback($value);
}
$dir === SORT_DESC ? arsort($results, $type) : asort($results, $type);
foreach (array_keys($results) as $key) {
$results[$key] = $items[$key];
}
parent::__construct($results);
}
示例3: __construct
/**
* Maintains an in-memory cache of the results yielded by the internal
* iterator.
*
* @param array|\Traversable $items The items to be filtered.
*/
public function __construct($items)
{
$this->_buffer = new SplDoublyLinkedList();
parent::__construct($items);
}
示例4: __construct
/**
* Creates an iterator from another iterator that will modify each of the values
* by converting them using a callback function.
*
* Each time the callback is executed it will receive the value of the element
* in the current iteration, the key of the element and the passed $items iterator
* as arguments, in that order.
*
* @param array|\Traversable $items The items to be filtered.
* @param callable $callback Callback.
*/
public function __construct($items, callable $callback)
{
$this->_callback = $callback;
parent::__construct($items);
$this->_innerIterator = $this->getInnerIterator();
}
示例5: __construct
/**
* Creates the iterator that will return the requested property for each value
* in the collection expressed in $path
*
* ### Example:
*
* Extract the user name for all comments in the array:
*
* {{{
* $items = [
* ['comment' => ['body' => 'cool', 'user' => ['name' => 'Mark']],
* ['comment' => ['body' => 'very cool', 'user' => ['name' => 'Renan']]
* ];
* $extractor = new ExtractIterator($items, 'comment.user.name'');
* }}}
*
* @param array|\Traversable $items The list of values to iterate
* @param string $path a dot separated string symbolizing the path to follow
* inside the hierarchy of each value so that the column can be extracted.
*/
public function __construct($items, $path)
{
$this->_path = explode('.', $path);
parent::__construct($items);
}
示例6: __construct
/**
* Constructor
*
* @param array|\Traversable $items Collection items.
* @param string|callable $nestKey the property that contains the nested items
* If a callable is passed, it should return the childrens for the passed item
*/
public function __construct($items, $nestKey)
{
parent::__construct($items);
$this->_nestKey = $nestKey;
}
示例7: __construct
/**
* Creates a filtered iterator using the callback to determine which items are
* accepted or rejected.
*
* Each time the callback is executed it will receive the value of the element
* in the current iteration, the key of the element and the passed $items iterator
* as arguments, in that order.
*
* @param Iterator $items The items to be filtered.
* @param callable $callback Callback.
*/
public function __construct(Iterator $items, callable $callback)
{
$wrapper = new CallbackFilterIterator($items, $callback);
parent::__construct($wrapper);
}
示例8: unserialize
/**
* Unserialize a resultset.
*
* Part of Serializable interface.
*
* @param string $serialized Serialized object
* @return void
*/
public function unserialize($serialized)
{
parent::__construct(unserialize($serialized));
}
示例9: __construct
/**
* Creates an iterator from another iterator that will modify each of the values
* by converting them using a callback function.
*
* Each time the callback is executed it will receive the value of the element
* in the current iteration, the key of the element and the passed $items iterator
* as arguments, in that order.
*
* @param array|\Traversable $items the items to be filtered
* @param callable $callback
*/
public function __construct($items, callable $callback)
{
$this->_callback = $callback;
parent::__construct($items);
}
示例10: __construct
/**
* Creates the iterator that will return the requested property for each value
* in the collection expressed in $path
*
* ### Example:
*
* Extract the user name for all comments in the array:
*
* ```
* $items = [
* ['comment' => ['body' => 'cool', 'user' => ['name' => 'Mark']],
* ['comment' => ['body' => 'very cool', 'user' => ['name' => 'Renan']]
* ];
* $extractor = new ExtractIterator($items, 'comment.user.name'');
* ```
*
* @param array|\Traversable $items The list of values to iterate
* @param string $path a dot separated string symbolizing the path to follow
* inside the hierarchy of each value so that the column can be extracted.
*/
public function __construct($items, $path)
{
$this->_extractor = $this->_propertyExtractor($path);
parent::__construct($items);
}
示例11: __construct
/**
* Creates an iterator that can be stopped based on a condition provided by a callback.
*
* Each time the condition callback is executed it will receive the value of the element
* in the current iteration, the key of the element and the passed $items iterator
* as arguments, in that order.
*
* @param array|\Traversable $items The list of values to iterate
* @param callable $condition A function that will be called for each item in
* the collection, if the result evaluates to false, no more items will be
* yielded from this iterator.
*/
public function __construct($items, callable $condition)
{
$this->_condition = $condition;
parent::__construct($items);
$this->_innnerIterator = $this->getInnerIterator();
}