Inheritance: implements Coduo\PHPMatcher\Matcher\ValueMatcher
Esempio n. 1
0
 /**
  * @param Request $request
  * @param Element $config
  * @return boolean
  */
 public function match(Request $request, Element $config)
 {
     if (!$config->getRequest()->hasHeaders()) {
         return true;
     }
     foreach ($config->getRequest()->getHeaders() as $headerName => $headerValuePattern) {
         if (!$request->headers->has($headerName)) {
             return false;
         }
         if (!$this->phpMatcher->match($request->headers->get($headerName), $headerValuePattern)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function match($value, $pattern)
 {
     if (parent::match($value, $pattern)) {
         return true;
     }
     if (!Xml::isValid($value) || !Xml::isValid($pattern)) {
         return false;
     }
     $arrayValue = XML2Array::createArray($value);
     $arrayPattern = XML2Array::createArray($pattern);
     $match = $this->matcher->match($arrayValue, $arrayPattern);
     if (!$match) {
         $this->error = $this->matcher->getError();
         return false;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * {@inheritDoc}
  */
 public function match($value, $pattern)
 {
     if (parent::match($value, $pattern)) {
         return true;
     }
     if (!is_array($value)) {
         $this->error = sprintf("%s \"%s\" is not a valid array.", gettype($value), new StringConverter($value));
         return false;
     }
     if ($this->isArrayPattern($pattern)) {
         return $this->allExpandersMatch($value, $pattern);
     }
     if (false === $this->iterateMatch($value, $pattern)) {
         return false;
     }
     return true;
 }
Esempio n. 4
0
 /**
  * {@inheritDoc}
  */
 public function match($value, $pattern)
 {
     if (parent::match($value, $pattern)) {
         return true;
     }
     if (!Json::isValid($value)) {
         $this->error = sprintf("Invalid given JSON of value. %s", $this->getErrorMessage());
         return false;
     }
     if (!Json::isValidPattern($pattern)) {
         $this->error = sprintf("Invalid given JSON of pattern. %s", $this->getErrorMessage());
         return false;
     }
     $transformedPattern = Json::transformPattern($pattern);
     $match = $this->matcher->match(json_decode($value, true), json_decode($transformedPattern, true));
     if (!$match) {
         $this->error = $this->matcher->getError();
         return false;
     }
     return true;
 }