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\Node\FeatureNode;
14 use Symfony\Component\Yaml\Yaml;
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 class YamlFileLoader extends AbstractFileLoader
25 public function __construct()
27 $this->loader = new ArrayLoader();
31 * Checks if current loader supports provided resource.
33 * @param mixed $path Resource to load
37 public function supports($path)
39 return is_string($path)
40 && is_file($absolute = $this->findAbsolutePath($path))
41 && 'yml' === pathinfo($absolute, PATHINFO_EXTENSION);
45 * Loads features from provided resource.
47 * @param string $path Resource to load
49 * @return FeatureNode[]
51 public function load($path)
53 $path = $this->findAbsolutePath($path);
54 $hash = Yaml::parse(file_get_contents($path));
56 $features = $this->loader->load($hash);
57 $filename = $this->findRelativePath($path);
59 return array_map(function (FeatureNode $feature) use ($filename) {
60 return new FeatureNode(
62 $feature->getDescription(),
64 $feature->getBackground(),
65 $feature->getScenarios(),
66 $feature->getKeyword(),
67 $feature->getLanguage(),