Example #1
0
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         $elementLength = strlen($model->{$element});
         if (!empty($this->params['min'])) {
             $this->params['min'] = filter_var($this->params['min'], FILTER_VALIDATE_INT);
             if ($this->params['min'] > $elementLength) {
                 $this->errors[] = $element . ' error: minimal characters not valid.';
                 return false;
             }
         }
         if (!empty($this->params['max'])) {
             $this->params['max'] = filter_var($this->params['max'], FILTER_VALIDATE_INT);
             if ($this->params['max'] < $elementLength) {
                 $this->errors[] = $element . ' error: maximal characters not valid.';
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             /** @var UploadedFileInterface[] $files */
             $files = (new RequestInjector())->build()->getUploadedFiles();
             if (!empty($this->params['maxFiles']) && count($files) > $this->params['maxFiles']) {
                 $this->errors[] = 'Too many files in parameter ' . $element;
                 return false;
             }
             foreach ($files as $fContext) {
                 if (!empty($this->params['types']) && strpos($this->params['types'], $fContext->getClientMediaType()) === false) {
                     $this->errors[] = 'File ' . $fContext->getClientFilename() . ' not allowed type';
                     return false;
                 }
                 if (!empty($this->params['minSize']) && $fContext->getSize() < $this->params['minSize']) {
                     $this->errors[] = 'File ' . $fContext->getClientFilename() . ' too small size';
                     return false;
                 }
                 if (!empty($this->params['maxSize']) && $fContext->getSize() > $this->params['maxSize']) {
                     $this->errors[] = 'File ' . $fContext->getClientFilename() . ' too many size';
                     return false;
                 }
             }
         }
     }
     return true;
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $files = $this->container->request->getFiles();
             if (!empty($this->params['maxFiles']) && count($files->files) > $this->params['maxFiles']) {
                 $this->errors[] = 'Too many files in parameter ' . $element;
                 return false;
             }
             foreach ($files->files as $fContext) {
                 if (!empty($this->params['types']) && strpos($this->params['types'], $fContext['type']) === false) {
                     $this->errors[] = 'File ' . $fContext['name'] . ' not allowed type';
                     return false;
                 }
                 if (!empty($this->params['minSize']) && $fContext['size'] < $this->params['minSize']) {
                     $this->errors[] = 'File ' . $fContext['name'] . ' too small size';
                     return false;
                 }
                 if (!empty($this->params['maxSize']) && $fContext['type'] > $this->params['maxSize']) {
                     $this->errors[] = 'File ' . $fContext['name'] . ' too many size';
                     return false;
                 }
             }
         }
     }
     return true;
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         if ($this->container->user->checkCaptcha($this->captcha)) {
             return false;
         }
     }
     return true;
 }
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         if (!is_numeric($model->{$element})) {
             $this->errors[] = 'Parameter ' . $element . ' is not a numeric';
         }
     }
     return true;
 }
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         if (!$model->{$element}) {
             $this->errors[] = $element . ' error: required element is empty.';
             return false;
         }
     }
     return true;
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         if (filter_var($model->{$element}, FILTER_VALIDATE_URL) === false) {
             $this->errors[] = 'Parameter ' . $element . ' is not a valid URL address';
             return false;
         }
     }
     return true;
 }
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         $elementValue = $model->{$element};
         if (preg_match($this->params['pattern'], $elementValue) === false) {
             $this->errors[] = 'Parameter ' . $element . ' not valid with regular expression';
             return false;
         }
     }
     return true;
 }
Example #9
0
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         $elementValue = $model->{$element};
         $query = new Query($this->container->db);
         $query->select = $this->params['attribute'];
         $query->table = $this->params['table'];
         $query->addWhere($this->params['attribute'] . '="' . $elementValue . '"');
         $query->limit = 1;
         $query->single = true;
         if ($query->run()) {
             return false;
         }
     }
     return true;
 }
 /**
  * @inheritdoc
  */
 public function validate(IFormModel $model)
 {
     if (empty($this->params['min'])) {
         $this->errors[] = 'Minimal value not declared to Range validator';
     }
     if (empty($this->params['max'])) {
         $this->errors[] = 'Maximal value not declared to Range validator';
     }
     $step = !empty($this->params['step']) ? $this->params['step'] : 1;
     $rang = range($this->params['min'], $this->params['max'], $step);
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         if (!in_array($model->{$element}, $rang, true)) {
             $this->errors[] = 'Parameter ' . $element . ' not find in rage ' . $this->params['min'] . '..' . $this->params['max'];
             return false;
         }
     }
     return true;
 }
Example #11
0
 /**
  * @inheritdoc
  * @throws Exception
  */
 public function validate(IFormModel $model)
 {
     if (empty($this->params['attribute']) && empty($this->params['value'])) {
         return false;
     }
     if (!$model->checkAttributeExists($this->params['attribute'])) {
         throw new Exception('Attribute `' . $this->params['attribute'] . '` not found into ' . get_class($model));
     }
     foreach ($this->elements as $element) {
         if (!$model->checkAttributeExists($element)) {
             $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model);
             return false;
         }
         $elementValue = $model->{$element};
         if (!empty($this->params['value']) && $this->params['value'] !== $elementValue) {
             $this->errors[] = 'Parameter ' . $element . ' not equal ' . $this->params['value'];
             return false;
         } elseif (!empty($this->params['attribute']) && $model->{$this->params['attribute']} !== $elementValue) {
             $this->errors[] = 'Parameter ' . $element . ' not equal ' . $model->{$this->params['attribute']};
             return false;
         }
     }
     return true;
 }
Example #12
0
 /**
  * Get errors from model
  *
  * @access public
  * @return array
  */
 public function getModelErrors()
 {
     return $this->model->getErrors();
 }