Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Loader / DirectoryLoader.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\Loader;
12
13 use Behat\Gherkin\Gherkin;
14 use Behat\Gherkin\Node\FeatureNode;
15 use RecursiveDirectoryIterator;
16 use RecursiveIteratorIterator;
17
18 /**
19  * Directory contents loader.
20  *
21  * @author Konstantin Kudryashov <ever.zet@gmail.com>
22  */
23 class DirectoryLoader extends AbstractFileLoader
24 {
25     protected $gherkin;
26
27     /**
28      * Initializes loader.
29      *
30      * @param Gherkin $gherkin Gherkin manager
31      */
32     public function __construct(Gherkin $gherkin)
33     {
34         $this->gherkin = $gherkin;
35     }
36
37     /**
38      * Checks if current loader supports provided resource.
39      *
40      * @param mixed $path Resource to load
41      *
42      * @return Boolean
43      */
44     public function supports($path)
45     {
46         return is_string($path)
47         && is_dir($this->findAbsolutePath($path));
48     }
49
50     /**
51      * Loads features from provided resource.
52      *
53      * @param string $path Resource to load
54      *
55      * @return FeatureNode[]
56      */
57     public function load($path)
58     {
59         $path = $this->findAbsolutePath($path);
60
61         $iterator = new RecursiveIteratorIterator(
62             new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)
63         );
64         $paths = array_map('strval', iterator_to_array($iterator));
65         uasort($paths, 'strnatcasecmp');
66
67         $features = array();
68
69         foreach ($paths as $path) {
70             $path = (string) $path;
71             $loader = $this->gherkin->resolveLoader($path);
72
73             if (null !== $loader) {
74                 $features = array_merge($features, $loader->load($path));
75             }
76         }
77
78         return $features;
79     }
80 }