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;
13 use Symfony\Component\Yaml\Exception\ParseException;
14 use Symfony\Component\Yaml\Yaml;
17 * Cucumber-translations reader.
19 * $keywords = new Behat\Gherkin\Keywords\CucumberKeywords($i18nYmlPath);
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 class CucumberKeywords extends ArrayKeywords
26 * Initializes holder with yaml string OR file.
28 * @param string $yaml Yaml string or file path
30 public function __construct($yaml)
32 // Handle filename explicitly for BC reasons, as Symfony Yaml 3.0 does not do it anymore
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));
40 $yaml = file_get_contents($file);
44 $content = Yaml::parse($yaml);
45 } catch (ParseException $e) {
47 $e->setParsedFile($file);
53 parent::__construct($content);
57 * Returns Feature keywords (splitted by "|").
61 public function getGivenKeywords()
63 return $this->prepareStepString(parent::getGivenKeywords());
67 * Returns When keywords (splitted by "|").
71 public function getWhenKeywords()
73 return $this->prepareStepString(parent::getWhenKeywords());
77 * Returns Then keywords (splitted by "|").
81 public function getThenKeywords()
83 return $this->prepareStepString(parent::getThenKeywords());
87 * Returns And keywords (splitted by "|").
91 public function getAndKeywords()
93 return $this->prepareStepString(parent::getAndKeywords());
97 * Returns But keywords (splitted by "|").
101 public function getButKeywords()
103 return $this->prepareStepString(parent::getButKeywords());
107 * Trim *| from the begining of the list.
109 * @param string $keywordsString Keywords string
113 private function prepareStepString($keywordsString)
115 if (0 === mb_strpos($keywordsString, '*|', 0, 'UTF-8')) {
116 $keywordsString = mb_substr($keywordsString, 2, mb_strlen($keywordsString, 'utf8') - 2, 'utf8');
119 return $keywordsString;