예제 #1
0
 /**
  * You should override this if you want a custom exception or if you want to have a ZeroId.
  *
  * @param int $id
  *
  * @throws InvalidArgumentException
  */
 protected function setId($id)
 {
     if (!Validator::isRequiredPositiveInteger($id)) {
         throw InvalidArgumentException::notPositiveInteger('id', $id);
     }
     $this->id = $id;
 }
예제 #2
0
 /**
  * @param string $idsStr Eg: '1, 3,  5, 10'
  *
  * @return IdSet
  *
  * @throws InvalidArgumentException
  */
 public static function fromString($idsStr)
 {
     if (!Validator::isOptionalString($idsStr)) {
         throw InvalidArgumentException::notString('ids', $idsStr);
     }
     $idsStr = preg_replace('/\\s+/', '', $idsStr);
     $idsArr = $idsStr == '' ? array() : explode(IdSet::DELIMITER, $idsStr);
     return static::fromArray($idsArr);
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function isOptionalNumberRange($value, $min, $max, $suppressException = true)
 {
     /* Clear the last error. */
     $this->lastError = null;
     /* If valid just return true. */
     if (Validator::isOptionalNumberRange($value, $min, $max)) {
         return true;
     }
     /* Set the error message. */
     $this->lastError = sprintf('Expects null or number in range [%d, %d], \'%d\' given.', $min, $max, is_scalar($value) ? $value : gettype($value));
     return $this->validationFailed($suppressException);
 }