Overview

Namespaces

  • None
  • Peridot
    • Leo
      • Formatter
      • Interfaces
        • Assert
      • Matcher
        • Template
      • ObjectPath
      • Responder
  • PHP

Classes

  • AbstractMatcher
  • CountableMatcher
  • EmptyMatcher
  • EqualMatcher
  • ExceptionMatcher
  • GreaterThanMatcher
  • GreaterThanOrEqualMatcher
  • InclusionMatcher
  • InstanceofMatcher
  • KeysMatcher
  • LengthMatcher
  • LessThanMatcher
  • LessThanOrEqualMatcher
  • Match
  • NullMatcher
  • PatternMatcher
  • PredicateMatcher
  • PropertyMatcher
  • RangeMatcher
  • SameMatcher
  • SubStringMatcher
  • TrueMatcher
  • TruthyMatcher
  • TypeMatcher

Interfaces

  • MatcherInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace Peridot\Leo\Matcher;
 3: 
 4: use Peridot\Leo\Matcher\Template\ArrayTemplate;
 5: use Peridot\Leo\Matcher\Template\TemplateInterface;
 6: 
 7: /**
 8:  * PatternMatcher determines if an actual string value matches a regular expression.
 9:  *
10:  * @package Peridot\Leo\Matcher
11:  */
12: class PatternMatcher extends AbstractMatcher
13: {
14:     /**
15:      * Match the actual value against a regular expression
16:      *
17:      * @param $actual
18:      * @return mixed
19:      */
20:     protected function doMatch($actual)
21:     {
22:         if (!is_string($actual)) {
23:             throw new \InvalidArgumentException("PatternMatcher expects a string");
24:         }
25: 
26:         return (bool) preg_match($this->expected, $actual);
27:     }
28: 
29:     /**
30:      * {@inheritdoc}
31:      *
32:      * @return TemplateInterface
33:      */
34:     public function getDefaultTemplate()
35:     {
36:         return new ArrayTemplate([
37:             'default' => 'Expected {{actual}} to match {{expected}}',
38:             'negated' => 'Expected {{actual}} not to match {{expected}}'
39:         ]);
40:     }
41: }
42: 
Leo API documentation generated by ApiGen