コード例 #1
0
 /**
  * Check rules for ComicVine API key.
  *
  * @param \ComicAPI\Tokens\TokenInterface $value Instance of Token.
  *
  * @return bool
  */
 protected function validComicVine(TokenInterface $value)
 {
     $valid = new Rules\AllOf(new Rules\Length(40), new Rules\StringType());
     if ($valid->validate($value->getToken()) === false) {
         return false;
     }
     return true;
 }
コード例 #2
0
 /**
  * Adds a single attribute to this validator.
  * @param string $field The attribute these rules apply to. Optionally specify a name for the rules by adding a
  *                      colon(":") followed by the name. E.g. "question:Security Question"
  * @param string $rule List of validators from the Respect\Validation package separated by the pipe ("|") character.
  */
 public function addAttribute($field, $rule)
 {
     $attributeRule = new AllOf();
     $attributeRule->addRules($this->createRulesArray($rule));
     $name = $field;
     // Get name if one was provided
     if (($colon = strpos($field, ':')) !== false) {
         $name = substr($field, $colon + 1);
         $field = substr($field, 0, $colon);
     }
     $attribute = new Key($field, $attributeRule);
     $attribute->setName($name);
     $this->addRule($attribute);
 }
コード例 #3
0
ファイル: Not.php プロジェクト: solleer/framework
 private function absorbAllOf(AllOf $rule, $input)
 {
     $rules = $rule->getRules();
     while ($current = array_shift($rules)) {
         $rule = $current;
         if (!$rule instanceof AllOf) {
             continue;
         }
         if (!$rule->validate($input)) {
             continue;
         }
         $rules = $rule->getRules();
     }
     return $rule;
 }
コード例 #4
0
ファイル: KeySet.php プロジェクト: nowsolutions/Validation
 /**
  * {@inheritdoc}
  */
 public function validate($input)
 {
     if (!$this->hasValidStructure($input)) {
         return false;
     }
     return parent::validate($input);
 }
コード例 #5
0
ファイル: Validator.php プロジェクト: Vaizard/Glued
 public function check($input)
 {
     try {
         return parent::check($input);
     } catch (ValidationException $exception) {
         if (count($this->getRules()) == 1 && $this->template) {
             $exception->setTemplate($this->template);
         }
         throw $exception;
     }
 }
コード例 #6
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);
     }
 }