本文整理汇总了PHP中Cake\Collection\Collection::each方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::each方法的具体用法?PHP Collection::each怎么用?PHP Collection::each使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Collection\Collection
的用法示例。
在下文中一共展示了Collection::each方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEeach
/**
* Test running a method over all elements in the collection
*
* @return void
*/
public function testEeach()
{
$items = ['a' => 1, 'b' => 2, 'c' => 3];
$collection = new Collection($items);
$callable = $this->getMock('stdClass', ['__invoke']);
$callable->expects($this->at(0))->method('__invoke')->with(1, 'a');
$callable->expects($this->at(1))->method('__invoke')->with(2, 'b');
$callable->expects($this->at(2))->method('__invoke')->with(3, 'c');
$collection->each($callable);
}
示例2: addPattern
/**
* addPattern
*
*/
public function addPattern($field, $pattern)
{
$pattern = new Collection((array) $pattern);
$validationSet = $this->field($field);
$validationPatterns = self::$validationPatterns;
$pattern->each(function ($key) use($field, $validationSet, $validationPatterns) {
if (empty($validationPatterns[$key])) {
if (method_exists($this, $key)) {
$this->{$key}($field);
return;
}
throw new NoValidationPatternException('Not found pattern `' . $key . '`');
}
$rules = new Collection($validationPatterns[$key]);
$rules->each(function ($rule, $name) use($validationSet) {
$validationSet->add($name, $rule);
});
});
return $this;
}