/**
  * 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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 4
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.'));
         }
     }
 }
Exemplo n.º 5
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.'));
         }
     }
 }