/** * {@inheritdoc} */ public function getConstraints() { $constraints = parent::getConstraints(); if ($this->requirements instanceof Constraint) { $constraints[] = $this->requirements; } $options = is_array($this->requirements) ? $this->requirements : array(); if ($this->image) { $constraints[] = new Constraints\Image($options); } else { $constraints[] = new Constraints\File($options); } return $constraints; }
/** {@inheritdoc} */ public function getConstraints() { $constraints = parent::getConstraints(); if ($this->requirements instanceof Constraint) { $constraints[] = $this->requirements; } elseif (is_scalar($this->requirements)) { $constraints[] = new Regex(array('pattern' => '#^(?:' . $this->requirements . ')$#xsu', 'message' => sprintf('Parameter \'%s\' value, does not match requirements \'%s\'', $this->getName(), $this->requirements))); } elseif (is_array($this->requirements) && isset($this->requirements['rule']) && $this->requirements['error_message']) { $constraints[] = new Regex(array('pattern' => '#^(?:' . $this->requirements['rule'] . ')$#xsu', 'message' => $this->requirements['error_message'])); } if (false === $this->allowBlank) { $constraints[] = new NotBlank(); } // If the user wants to map the value if ($this->map) { $constraints = array(new All($constraints)); } return $constraints; }
/** {@inheritdoc} */ public function getConstraints() { $constraints = parent::getConstraints(); $constraints[] = new Constraints\Type(array('type' => 'scalar')); $requirements = $this->resolve($this->requirements); if ($this->requirements instanceof Constraint) { $constraints[] = $requirements; } elseif (is_scalar($requirements)) { $constraints[] = new Constraints\Regex(array('pattern' => '#^(?:' . $requirements . ')$#xsu', 'message' => sprintf('Parameter \'%s\' value, does not match requirements \'%s\'', $this->getName(), $requirements))); } elseif (is_array($requirements) && isset($requirements['rule']) && $requirements['error_message']) { $constraints[] = new Constraints\Regex(array('pattern' => '#^(?:' . $requirements['rule'] . ')$#xsu', 'message' => $requirements['error_message'])); } if (false === $this->allowBlank) { $constraints[] = new Constraints\NotBlank(); } // If an array is expected apply the constraints to each element. if ($this->array) { $constraints = array(new Constraints\All($constraints)); } return $constraints; }