コード例 #1
0
ファイル: Length.php プロジェクト: dez-php/Validation
 public function __construct($min = null, $max = null, $inclusive = true)
 {
     $this->minValue = $min;
     $this->maxValue = $max;
     $this->inclusive = $inclusive;
     $paramValidator = new OneOf(new Numeric(), new NullType());
     if (!$paramValidator->validate($min)) {
         throw new ComponentException(sprintf('%s is not a valid numeric length', $min));
     }
     if (!$paramValidator->validate($max)) {
         throw new ComponentException(sprintf('%s is not a valid numeric length', $max));
     }
     if (!is_null($min) && !is_null($max) && $min > $max) {
         throw new ComponentException(sprintf('%s cannot be less than %s for validation', $min, $max));
     }
 }
コード例 #2
0
ファイル: Request.php プロジェクト: grz-gajda/comic-api
 /**
  * Validate filters or throws an exception.
  *
  * @param array                   $filters          List of filters
  * @param Rules\AllOf|Rules\OneOf $callable         Validation rules
  * @param string                  $exceptionMessage Exception message
  *
  * @throws \ComicAPI\Exceptions\ComicApiException
  */
 protected function validateFilters($filters, $callable, $exceptionMessage = "Invalid list of filters.")
 {
     if ($callable->validate($filters) === false) {
         throw new ComicApiException($exceptionMessage);
     }
 }