Ejemplo n.º 1
0
 /**
  * Validate the entire form data set against each field's validators, and additionally validate interdependent fields.
  *
  * @return boolean True if each of the container's fields validates, and additionally if the dependencies validate; otherwise false.
  */
 public function isValid()
 {
     $valid = parent::isValid();
     $setPasswordField = $this->getField('setpass');
     if (!$setPasswordField->hasErrorMessage() && $setPasswordField->getData()) {
         $passwordField = $this->getField('pass');
         if (!$this->passwordLengthValidator->isValid($passwordField->getData())) {
             $passwordField->setErrorMessage($this->passwordLengthValidator->getErrorMessage());
         }
         $passwordAgainField = $this->getField('passagain');
         if (!$passwordField->hasErrorMessage() && !$passwordAgainField->hasErrorMessage()) {
             $password = $passwordField->getData();
             $passwordAgain = $passwordAgainField->getData();
             if ($passwordAgain != $password) {
                 $valid = false;
                 $passwordAgainField->setErrorMessage($this->__('The value entered does not match the password entered in the password field.'));
             }
         }
     }
     $emailField = $this->getField('email');
     if (!$emailField->hasErrorMessage()) {
         $emailAgainField = $this->getField('emailagain');
         $email = $emailField->getData();
         $emailAgain = $emailAgainField->getData();
         if ($email != $emailAgain) {
             $valid = false;
             $emailAgainField->setErrorMessage($this->__('The value entered does not match the e-mail address entered in the e-mail address field.'));
         }
     }
     return $valid;
 }
 /**
  * Constructs a new validator, initializing the maximum valid value.
  *
  * @param ContainerBuilder $container The current service manager instance.
  * @param integer        $value          The maximum valid value for the field data.
  * @param string         $errorMessage   The error message to return if the field data is not valid.
  *
  * @throws \InvalidArgumentException If the maximum value specified is not an integer.
  */
 public function __construct(ContainerBuilder $container, $value, $errorMessage = null)
 {
     parent::__construct($container, $errorMessage);
     if (!isset($value) || !is_int($value) || $value < 0) {
         throw new \InvalidArgumentException($this->__('An invalid integer value was received.'));
     }
     $this->value = $value;
 }
Ejemplo n.º 3
0
 /**
  * Constructs a new validator, initializing the maximum valid string length value.
  *
  * @param ContainerBuilder $container The current service manager instance.
  * @param integer        $length         The maximum valid length for the string value.
  * @param string         $errorMessage   The error message to return if the string data exceeds the maximum length.
  *
  * @throws \InvalidArgumentException Thrown if the maximum string length value is not an integer or is less than
  * zero.
  */
 public function __construct(ContainerBuilder $container, $length, $errorMessage = null)
 {
     parent::__construct($container, $errorMessage);
     if (!isset($length) || !is_int($length) || $length < 0) {
         throw new \InvalidArgumentException($this->__('An invalid string length was received.'));
     }
     $this->length = $length;
 }
 /**
  * Constructs the validator, initializing the regular expression.
  *
  * @param ContainerBuilder $container    The current service manager instance.
  * @param string         $regularExpression The PCRE regular expression against which to validate the data.
  * @param string         $errorMessage      The error message to return if the data does not match the expression.
  *
  * @throws \InvalidArgumentException Thrown if the regular expression is not valid.
  */
 public function __construct(ContainerBuilder $container, $regularExpression, $errorMessage = null)
 {
     parent::__construct($container, $errorMessage);
     if (!isset($regularExpression) || !is_string($regularExpression) || empty($regularExpression)) {
         throw new \InvalidArgumentException($this->__('An invalid regular expression was recieved.'));
     }
     $this->regularExpression = $regularExpression;
 }
Ejemplo n.º 5
0
 /**
  * Creates a new validator, initializing the set of valid string values.
  *
  * @param ContainerBuilder $container The current service manager instance.
  * @param array          $validStrings   An array containing valid string values.
  * @param string         $errorMessage   The error message to return if the data is not valid.
  *
  * @throws \InvalidArgumentException Thrown if the list of valid string values is not valid,
  * or if it contains an invalid value.
  */
 public function __construct(ContainerBuilder $container, array $validStrings, $errorMessage = null)
 {
     parent::__construct($container, $errorMessage);
     if (empty($validStrings)) {
         throw new \InvalidArgumentException($this->__('An invalid list of valid strings was received.'));
     }
     foreach ($validStrings as $validString) {
         if (isset($validString) && is_string($validString)) {
             $this->validStrings[$validString] = $validString;
         } else {
             throw new InvalidArgumentException($this->__('An invalid value was received in the list of valid strings.'));
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Creates a new instance of this validator, intializing the list of valid integers.
  *
  * @param ContainerBuilder $container The current service manager.
  * @param array           $validIntegers  An array containing a list of integers considered to be valid for the
  *                                        field's data contents.
  * @param string          $errorMessage   The message to return if the data is not valid.
  *
  * @throws \InvalidArgumentException Thrown if the list of valid integer numerics is invalid,
  * or if it contains an invalid value.
  */
 public function __construct(ContainerBuilder $container, array $validIntegers, $errorMessage = null)
 {
     parent::__construct($container, $errorMessage);
     if (empty($validIntegers)) {
         throw new \InvalidArgumentException($this->__('An invalid list of valid integers was recieved.'));
     }
     foreach ($validIntegers as $validInteger) {
         if (isset($validInteger) && is_int($validInteger)) {
             $this->validIntegers[$validInteger] = $validInteger;
         } else {
             throw new \InvalidArgumentException($this->__('An invalid value was received in the list of valid
             integers.'));
         }
     }
 }