/**
  * 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;
 }
Esempio n. 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);
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function validate($input)
 {
     if (!$this->hasValidStructure($input)) {
         return false;
     }
     return parent::validate($input);
 }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
 /**
  * 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);
     }
 }