Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Hook / Context / Annotation / HookAnnotationReader.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\Hook\Context\Annotation;
12
13 use Behat\Behat\Context\Annotation\AnnotationReader;
14 use Behat\Testwork\Hook\Call\RuntimeHook;
15 use ReflectionMethod;
16
17 /**
18  * Reads hook callees from context method annotations.
19  *
20  * @author Konstantin Kudryashov <ever.zet@gmail.com>
21  */
22 final class HookAnnotationReader implements AnnotationReader
23 {
24     /**
25      * @var string
26      */
27     private static $regex = '/^\@(beforesuite|aftersuite|beforefeature|afterfeature|beforescenario|afterscenario|beforestep|afterstep)(?:\s+(.+))?$/i';
28     /**
29      * @var string[]
30      */
31     private static $classes = array(
32         'beforesuite'    => 'Behat\Testwork\Hook\Call\BeforeSuite',
33         'aftersuite'     => 'Behat\Testwork\Hook\Call\AfterSuite',
34         'beforefeature'  => 'Behat\Behat\Hook\Call\BeforeFeature',
35         'afterfeature'   => 'Behat\Behat\Hook\Call\AfterFeature',
36         'beforescenario' => 'Behat\Behat\Hook\Call\BeforeScenario',
37         'afterscenario'  => 'Behat\Behat\Hook\Call\AfterScenario',
38         'beforestep'     => 'Behat\Behat\Hook\Call\BeforeStep',
39         'afterstep'      => 'Behat\Behat\Hook\Call\AfterStep'
40     );
41
42     /**
43      * Loads step callees (if exist) associated with specific method.
44      *
45      * @param string           $contextClass
46      * @param ReflectionMethod $method
47      * @param string           $docLine
48      * @param string           $description
49      *
50      * @return null|RuntimeHook
51      */
52     public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description)
53     {
54         if (!preg_match(self::$regex, $docLine, $match)) {
55             return null;
56         }
57
58         $type = strtolower($match[1]);
59         $class = self::$classes[$type];
60         $pattern = isset($match[2]) ? $match[2] : null;
61         $callable = array($contextClass, $method->getName());
62
63         return new $class($pattern, $callable, $description);
64     }
65 }