Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Keywords / ArrayKeywords.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 /**
14  * Array initializable keywords holder.
15  *
16  * $keywords = new Behat\Gherkin\Keywords\ArrayKeywords(array(
17  *     'en' => array(
18  *         'feature'          => 'Feature',
19  *         'background'       => 'Background',
20  *         'scenario'         => 'Scenario',
21  *         'scenario_outline' => 'Scenario Outline|Scenario Template',
22  *         'examples'         => 'Examples|Scenarios',
23  *         'given'            => 'Given',
24  *         'when'             => 'When',
25  *         'then'             => 'Then',
26  *         'and'              => 'And',
27  *         'but'              => 'But'
28  *     ),
29  *     'ru' => array(
30  *         'feature'          => 'Функционал',
31  *         'background'       => 'Предыстория',
32  *         'scenario'         => 'Сценарий',
33  *         'scenario_outline' => 'Структура сценария',
34  *         'examples'         => 'Значения',
35  *         'given'            => 'Допустим',
36  *         'when'             => 'Если',
37  *         'then'             => 'То',
38  *         'and'              => 'И',
39  *         'but'              => 'Но'
40  *     )
41  * ));
42  *
43  * @author Konstantin Kudryashov <ever.zet@gmail.com>
44  */
45 class ArrayKeywords implements KeywordsInterface
46 {
47     private $keywords = array();
48     private $keywordString = array();
49     private $language;
50
51     /**
52      * Initializes holder with keywords.
53      *
54      * @param array $keywords Keywords array
55      */
56     public function __construct(array $keywords)
57     {
58         $this->keywords = $keywords;
59     }
60
61     /**
62      * Sets keywords holder language.
63      *
64      * @param string $language Language name
65      */
66     public function setLanguage($language)
67     {
68         if (!isset($this->keywords[$language])) {
69             $this->language = 'en';
70         } else {
71             $this->language = $language;
72         }
73     }
74
75     /**
76      * Returns Feature keywords (splitted by "|").
77      *
78      * @return string
79      */
80     public function getFeatureKeywords()
81     {
82         return $this->keywords[$this->language]['feature'];
83     }
84
85     /**
86      * Returns Background keywords (splitted by "|").
87      *
88      * @return string
89      */
90     public function getBackgroundKeywords()
91     {
92         return $this->keywords[$this->language]['background'];
93     }
94
95     /**
96      * Returns Scenario keywords (splitted by "|").
97      *
98      * @return string
99      */
100     public function getScenarioKeywords()
101     {
102         return $this->keywords[$this->language]['scenario'];
103     }
104
105     /**
106      * Returns Scenario Outline keywords (splitted by "|").
107      *
108      * @return string
109      */
110     public function getOutlineKeywords()
111     {
112         return $this->keywords[$this->language]['scenario_outline'];
113     }
114
115     /**
116      * Returns Examples keywords (splitted by "|").
117      *
118      * @return string
119      */
120     public function getExamplesKeywords()
121     {
122         return $this->keywords[$this->language]['examples'];
123     }
124
125     /**
126      * Returns Given keywords (splitted by "|").
127      *
128      * @return string
129      */
130     public function getGivenKeywords()
131     {
132         return $this->keywords[$this->language]['given'];
133     }
134
135     /**
136      * Returns When keywords (splitted by "|").
137      *
138      * @return string
139      */
140     public function getWhenKeywords()
141     {
142         return $this->keywords[$this->language]['when'];
143     }
144
145     /**
146      * Returns Then keywords (splitted by "|").
147      *
148      * @return string
149      */
150     public function getThenKeywords()
151     {
152         return $this->keywords[$this->language]['then'];
153     }
154
155     /**
156      * Returns And keywords (splitted by "|").
157      *
158      * @return string
159      */
160     public function getAndKeywords()
161     {
162         return $this->keywords[$this->language]['and'];
163     }
164
165     /**
166      * Returns But keywords (splitted by "|").
167      *
168      * @return string
169      */
170     public function getButKeywords()
171     {
172         return $this->keywords[$this->language]['but'];
173     }
174
175     /**
176      * Returns all step keywords (Given, When, Then, And, But).
177      *
178      * @return string
179      */
180     public function getStepKeywords()
181     {
182         if (!isset($this->keywordString[$this->language])) {
183             $keywords = array_merge(
184                 explode('|', $this->getGivenKeywords()),
185                 explode('|', $this->getWhenKeywords()),
186                 explode('|', $this->getThenKeywords()),
187                 explode('|', $this->getAndKeywords()),
188                 explode('|', $this->getButKeywords())
189             );
190
191             usort($keywords, function ($keyword1, $keyword2) {
192                 return mb_strlen($keyword2, 'utf8') - mb_strlen($keyword1, 'utf8');
193             });
194
195             $this->keywordString[$this->language] = implode('|', $keywords);
196         }
197
198         return $this->keywordString[$this->language];
199     }
200 }