Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / Context / Annotation / DefinitionAnnotationReader.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Definition\Context\Annotation;
12
13 use Behat\Behat\Context\Annotation\AnnotationReader;
14 use ReflectionMethod;
15
16 /**
17  * Reads definition annotations from the context class.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 final class DefinitionAnnotationReader implements AnnotationReader
22 {
23     /**
24      * @var string
25      */
26     private static $regex = '/^\@(given|when|then)\s+(.+)$/i';
27     /**
28      * @var string[]
29      */
30     private static $classes = array(
31         'given' => 'Behat\Behat\Definition\Call\Given',
32         'when'  => 'Behat\Behat\Definition\Call\When',
33         'then'  => 'Behat\Behat\Definition\Call\Then',
34     );
35
36     /**
37      * {@inheritdoc}
38      */
39     public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description)
40     {
41         if (!preg_match(self::$regex, $docLine, $match)) {
42             return null;
43         }
44
45         $type = strtolower($match[1]);
46         $class = self::$classes[$type];
47         $pattern = $match[2];
48         $callable = array($contextClass, $method->getName());
49
50         return new $class($pattern, $callable, $description);
51     }
52 }