Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Loader / YamlFileLoader.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\Node\FeatureNode;
14 use Symfony\Component\Yaml\Yaml;
15
16 /**
17  * Yaml files loader.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 class YamlFileLoader extends AbstractFileLoader
22 {
23     private $loader;
24
25     public function __construct()
26     {
27         $this->loader = new ArrayLoader();
28     }
29
30     /**
31      * Checks if current loader supports provided resource.
32      *
33      * @param mixed $path Resource to load
34      *
35      * @return Boolean
36      */
37     public function supports($path)
38     {
39         return is_string($path)
40             && is_file($absolute = $this->findAbsolutePath($path))
41             && 'yml' === pathinfo($absolute, PATHINFO_EXTENSION);
42     }
43
44     /**
45      * Loads features from provided resource.
46      *
47      * @param string $path Resource to load
48      *
49      * @return FeatureNode[]
50      */
51     public function load($path)
52     {
53         $path = $this->findAbsolutePath($path);
54         $hash = Yaml::parse(file_get_contents($path));
55
56         $features = $this->loader->load($hash);
57         $filename = $this->findRelativePath($path);
58
59         return array_map(function (FeatureNode $feature) use ($filename) {
60             return new FeatureNode(
61                 $feature->getTitle(),
62                 $feature->getDescription(),
63                 $feature->getTags(),
64                 $feature->getBackground(),
65                 $feature->getScenarios(),
66                 $feature->getKeyword(),
67                 $feature->getLanguage(),
68                 $filename,
69                 $feature->getLine()
70             );
71         }, $features);
72     }
73 }