示例#1
0
 /**
  * I do extra check so $this->_options['enum'] is an array
  * @param null $options
  * @throws \Exception
  */
 public function __construct($options = null)
 {
     if (!is_array($options['enum'])) {
         throw new \Exception('expected array as enum');
     }
     parent::__construct($options);
 }
示例#2
0
 /**
  * I do extra check so $this->_options['callback'] is a callable for sure
  * @param null $options
  * @throws \Exception
  */
 public function __construct($options = null)
 {
     if (!is_callable($options['callback'])) {
         throw new \Exception('expected valid callback');
     }
     parent::__construct($options);
 }
示例#3
0
 /**
  * Class constructor.
  *
  * @param  array $options
  * @param  DbConnection  $db
  * @throws ValidationException
  */
 public function __construct(array $options = [], DbConnection $db = null)
 {
     parent::__construct($options);
     if (!$db) {
         // try to get db instance from default Dependency Injection
         $di = Di::getDefault();
         if ($di instanceof DiInterface && $di->has('db')) {
             $db = $di->get('db');
         }
     }
     if (!$db instanceof DbConnection) {
         throw new ValidationException('Validator Uniqueness require connection to database');
     }
     if (!$this->hasOption('table')) {
         throw new ValidationException('Validator require table option to be set');
     }
     if (!$this->hasOption('column')) {
         throw new ValidationException('Validator require column option to be set');
     }
     if ($this->hasOption('exclude')) {
         $exclude = $this->getOption('exclude');
         if (!isset($exclude['column']) || empty($exclude['column'])) {
             throw new ValidationException('Validator with "exclude" option require column option to be set');
         }
         if (!isset($exclude['value']) || empty($exclude['value'])) {
             throw new ValidationException('Validator with "exclude" option require value option to be set');
         }
     }
     $this->db = $db;
 }
示例#4
0
 /**
  * Executes the validation
  *
  * @param Validator $validator
  * @param string $attribute
  * @return \Phalcon\Validation\Message\Group
  */
 public function validate($validator, $attribute)
 {
     /* @var Validator $validator */
     $values = $validator->getValue($attribute);
     $result = true;
     if ($this->elementsValidator) {
         $validation = new Validation();
         foreach ($values as $index => $element) {
             $validation->add($index, $this->elementsValidator);
         }
         $messages = $validation->validate($values);
         if (count($messages)) {
             foreach ($messages as $message) {
                 $validator->appendMessage($message);
             }
             $result = false;
         }
     }
     return $result;
 }
示例#5
0
 /**
  * Class constructor.
  *
  * @param  array               $options
  * @param  DbConnection        $db
  * @throws ValidationException
  */
 public function __construct(array $options = array(), $db = null)
 {
     parent::__construct($options);
     if (null === $db) {
         // try to get db instance from default Dependency Injection
         $di = Di::getDefault();
         if ($di instanceof DiInterface && $di->has('db')) {
             $db = $di->get('db');
         }
     }
     if (!$db instanceof DbConnection) {
         throw new ValidationException('Validator Uniquness require connection to database');
     }
     if (false === $this->isSetOption('table')) {
         throw new ValidationException('Validator require table option to be set');
     }
     if (false === $this->isSetOption('column')) {
         throw new ValidationException('Validator require column option to be set');
     }
     $this->db = $db;
 }
示例#6
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     $this->setOption('cancelOnFail', TRUE);
 }
 public function __construct($db, $options = [])
 {
     parent::__construct($options);
     $this->db = $db;
 }