Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Filter / PathsFilter.php
1 <?php
2
3 /*
4  * This file is part of the Behat Gherkin.
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\Gherkin\Filter;
12
13 use Behat\Gherkin\Node\FeatureNode;
14 use Behat\Gherkin\Node\ScenarioInterface;
15
16 /**
17  * Filters features by their paths.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 class PathsFilter extends SimpleFilter
22 {
23     protected $filterPaths = array();
24
25     /**
26      * Initializes filter.
27      *
28      * @param string[] $paths List of approved paths
29      */
30     public function __construct(array $paths)
31     {
32         $this->filterPaths = array_map(
33             function ($realpath) {
34                 return rtrim($realpath, DIRECTORY_SEPARATOR) .
35                     (is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
36             },
37             array_filter(
38                 array_map('realpath', $paths)
39             )
40         );
41     }
42
43     /**
44      * Checks if Feature matches specified filter.
45      *
46      * @param FeatureNode $feature Feature instance
47      *
48      * @return Boolean
49      */
50     public function isFeatureMatch(FeatureNode $feature)
51     {
52         foreach ($this->filterPaths as $path) {
53             if (0 === strpos(realpath($feature->getFile()), $path)) {
54                 return true;
55             }
56         }
57
58         return false;
59     }
60
61     /**
62      * Checks if scenario or outline matches specified filter.
63      *
64      * @param ScenarioInterface $scenario Scenario or Outline node instance
65      *
66      * @return false This filter is designed to work only with features
67      */
68     public function isScenarioMatch(ScenarioInterface $scenario)
69     {
70         return false;
71     }
72 }