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\Keywords;
14 * Array initializable keywords holder.
16 * $keywords = new Behat\Gherkin\Keywords\ArrayKeywords(array(
18 * 'feature' => 'Feature',
19 * 'background' => 'Background',
20 * 'scenario' => 'Scenario',
21 * 'scenario_outline' => 'Scenario Outline|Scenario Template',
22 * 'examples' => 'Examples|Scenarios',
30 * 'feature' => 'Функционал',
31 * 'background' => 'Предыстория',
32 * 'scenario' => 'Сценарий',
33 * 'scenario_outline' => 'Структура сценария',
34 * 'examples' => 'Значения',
35 * 'given' => 'Допустим',
43 * @author Konstantin Kudryashov <ever.zet@gmail.com>
45 class ArrayKeywords implements KeywordsInterface
47 private $keywords = array();
48 private $keywordString = array();
52 * Initializes holder with keywords.
54 * @param array $keywords Keywords array
56 public function __construct(array $keywords)
58 $this->keywords = $keywords;
62 * Sets keywords holder language.
64 * @param string $language Language name
66 public function setLanguage($language)
68 if (!isset($this->keywords[$language])) {
69 $this->language = 'en';
71 $this->language = $language;
76 * Returns Feature keywords (splitted by "|").
80 public function getFeatureKeywords()
82 return $this->keywords[$this->language]['feature'];
86 * Returns Background keywords (splitted by "|").
90 public function getBackgroundKeywords()
92 return $this->keywords[$this->language]['background'];
96 * Returns Scenario keywords (splitted by "|").
100 public function getScenarioKeywords()
102 return $this->keywords[$this->language]['scenario'];
106 * Returns Scenario Outline keywords (splitted by "|").
110 public function getOutlineKeywords()
112 return $this->keywords[$this->language]['scenario_outline'];
116 * Returns Examples keywords (splitted by "|").
120 public function getExamplesKeywords()
122 return $this->keywords[$this->language]['examples'];
126 * Returns Given keywords (splitted by "|").
130 public function getGivenKeywords()
132 return $this->keywords[$this->language]['given'];
136 * Returns When keywords (splitted by "|").
140 public function getWhenKeywords()
142 return $this->keywords[$this->language]['when'];
146 * Returns Then keywords (splitted by "|").
150 public function getThenKeywords()
152 return $this->keywords[$this->language]['then'];
156 * Returns And keywords (splitted by "|").
160 public function getAndKeywords()
162 return $this->keywords[$this->language]['and'];
166 * Returns But keywords (splitted by "|").
170 public function getButKeywords()
172 return $this->keywords[$this->language]['but'];
176 * Returns all step keywords (Given, When, Then, And, But).
180 public function getStepKeywords()
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())
191 usort($keywords, function ($keyword1, $keyword2) {
192 return mb_strlen($keyword2, 'utf8') - mb_strlen($keyword1, 'utf8');
195 $this->keywordString[$this->language] = implode('|', $keywords);
198 return $this->keywordString[$this->language];