Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Keywords / CucumberKeywords.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\Keywords;
12
13 use Symfony\Component\Yaml\Exception\ParseException;
14 use Symfony\Component\Yaml\Yaml;
15
16 /**
17  * Cucumber-translations reader.
18  *
19  * $keywords = new Behat\Gherkin\Keywords\CucumberKeywords($i18nYmlPath);
20  *
21  * @author Konstantin Kudryashov <ever.zet@gmail.com>
22  */
23 class CucumberKeywords extends ArrayKeywords
24 {
25     /**
26      * Initializes holder with yaml string OR file.
27      *
28      * @param string $yaml Yaml string or file path
29      */
30     public function __construct($yaml)
31     {
32         // Handle filename explicitly for BC reasons, as Symfony Yaml 3.0 does not do it anymore
33         $file = null;
34         if (strpos($yaml, "\n") === false && is_file($yaml)) {
35             if (false === is_readable($yaml)) {
36                 throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $yaml));
37             }
38
39             $file = $yaml;
40             $yaml = file_get_contents($file);
41         }
42
43         try {
44             $content = Yaml::parse($yaml);
45         } catch (ParseException $e) {
46             if ($file) {
47                 $e->setParsedFile($file);
48             }
49
50             throw $e;
51         }
52
53         parent::__construct($content);
54     }
55
56     /**
57      * Returns Feature keywords (splitted by "|").
58      *
59      * @return string
60      */
61     public function getGivenKeywords()
62     {
63         return $this->prepareStepString(parent::getGivenKeywords());
64     }
65
66     /**
67      * Returns When keywords (splitted by "|").
68      *
69      * @return string
70      */
71     public function getWhenKeywords()
72     {
73         return $this->prepareStepString(parent::getWhenKeywords());
74     }
75
76     /**
77      * Returns Then keywords (splitted by "|").
78      *
79      * @return string
80      */
81     public function getThenKeywords()
82     {
83         return $this->prepareStepString(parent::getThenKeywords());
84     }
85
86     /**
87      * Returns And keywords (splitted by "|").
88      *
89      * @return string
90      */
91     public function getAndKeywords()
92     {
93         return $this->prepareStepString(parent::getAndKeywords());
94     }
95
96     /**
97      * Returns But keywords (splitted by "|").
98      *
99      * @return string
100      */
101     public function getButKeywords()
102     {
103         return $this->prepareStepString(parent::getButKeywords());
104     }
105
106     /**
107      * Trim *| from the begining of the list.
108      *
109      * @param string $keywordsString Keywords string
110      *
111      * @return string
112      */
113     private function prepareStepString($keywordsString)
114     {
115         if (0 === mb_strpos($keywordsString, '*|', 0, 'UTF-8')) {
116             $keywordsString = mb_substr($keywordsString, 2, mb_strlen($keywordsString, 'utf8') - 2, 'utf8');
117         }
118
119         return $keywordsString;
120     }
121 }