예제 #1
0
 /**
  * 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
0
 /**
  * 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;
 }