4 * This file is part of the Behat Gherkin.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Gherkin\Loader;
13 use Behat\Gherkin\Gherkin;
14 use Behat\Gherkin\Node\FeatureNode;
15 use RecursiveDirectoryIterator;
16 use RecursiveIteratorIterator;
19 * Directory contents loader.
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 class DirectoryLoader extends AbstractFileLoader
30 * @param Gherkin $gherkin Gherkin manager
32 public function __construct(Gherkin $gherkin)
34 $this->gherkin = $gherkin;
38 * Checks if current loader supports provided resource.
40 * @param mixed $path Resource to load
44 public function supports($path)
46 return is_string($path)
47 && is_dir($this->findAbsolutePath($path));
51 * Loads features from provided resource.
53 * @param string $path Resource to load
55 * @return FeatureNode[]
57 public function load($path)
59 $path = $this->findAbsolutePath($path);
61 $iterator = new RecursiveIteratorIterator(
62 new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)
64 $paths = array_map('strval', iterator_to_array($iterator));
65 uasort($paths, 'strnatcasecmp');
69 foreach ($paths as $path) {
70 $path = (string) $path;
71 $loader = $this->gherkin->resolveLoader($path);
73 if (null !== $loader) {
74 $features = array_merge($features, $loader->load($path));