Example #1
0
 public function testThatOptionalValueIsReturnedAsValueWhenRuleThrowsEmptyException()
 {
     $this->validator->addClosureRule(function ($something) {
         if ($something === NULL) {
             throw EmptyDataException::factory(array());
         }
         return $something;
     }, 'some');
     $this->validator->setOptional('some');
     $this->assertValid('some', NULL, array());
 }
 public function validate($data)
 {
     if ($data === NULL || $data === array()) {
         throw EmptyDataException::factory(array());
     }
     $data = (array) $data;
     if (count($data) == 0) {
         throw EmptyDataException::factory(array());
     }
     return $data;
 }
Example #3
0
 public static function factory($defaultValue, \Exception $previous = NULL)
 {
     $e = new EmptyDataException(NULL, 0, $previous);
     $e->setDefaultValue($defaultValue);
     return $e;
 }
 protected function emptyException($previous = NULL)
 {
     return EmptyDataException::factory(array_fill_keys($this->languages, NULL), $previous);
 }