Inheritance: extends Phalcon\Validation\Validator
示例#1
0
 public function testEmptyMongoIdValueWithAllowEmptyOption()
 {
     $array = ['id' => ''];
     $this->testable->setOption('allowEmpty', true);
     $this->validation->add('id', $this->testable);
     $messages = $this->validation->validate($array);
     $this->assertEquals(0, count($messages));
 }
示例#2
0
 /**
  * @param Validation $validation
  * @param string $attribute
  * @return bool
  * @throws Exception
  */
 public function validate(Validation $validation, $attribute)
 {
     if (!extension_loaded('mongo')) {
         throw new Exception('Mongo extension is not available');
     }
     $value = $validation->getValue($attribute);
     $allowEmpty = $this->hasOption('allowEmpty');
     $result = $allowEmpty && empty($value) ? true : Id::isValid($value);
     if (!$result) {
         $message = $this->hasOption('message') ? $this->getOption('message') : 'MongoId is not valid';
         $validation->appendMessage(new Message($message, $attribute, 'MongoId'));
     }
     return $result;
 }