| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Behat Gherkin. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * (c) Konstantin Kudryashov <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 | 248 |  |     public function __construct(array $keywords) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 248 |  |         $this->keywords = $keywords; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 248 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Sets keywords holder language. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param string $language Language name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 246 |  |     public function setLanguage($language) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 246 |  |         if (!isset($this->keywords[$language])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 3 |  |             $this->language = 'en'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 246 |  |             $this->language = $language; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 246 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * Returns Feature keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 173 |  |     public function getFeatureKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 173 |  |         return $this->keywords[$this->language]['feature']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * Returns Background keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 173 |  |     public function getBackgroundKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 173 |  |         return $this->keywords[$this->language]['background']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * Returns Rule keywords (splitted by "|") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 242 |  |     public function getRuleKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 242 |  |         return $this->keywords[$this->language]['rule']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * Returns Scenario keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 173 |  |     public function getScenarioKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 173 |  |         return $this->keywords[$this->language]['scenario']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * Returns Scenario Outline keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 173 |  |     public function getOutlineKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 173 |  |         return $this->keywords[$this->language]['scenario_outline']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * Returns Examples keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 173 |  |     public function getExamplesKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 173 |  |         return $this->keywords[$this->language]['examples']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * Returns Given keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 139 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 140 | 169 |  |     public function getGivenKeywords() | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 142 | 169 |  |         return $this->keywords[$this->language]['given']; | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * Returns When keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 169 |  |     public function getWhenKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 169 |  |         return $this->keywords[$this->language]['when']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      * Returns Then keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 169 |  |     public function getThenKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 169 |  |         return $this->keywords[$this->language]['then']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * Returns And keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 | 169 |  |     public function getAndKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 169 |  |         return $this->keywords[$this->language]['and']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * Returns But keywords (splitted by "|"). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 169 |  |     public function getButKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 169 |  |         return $this->keywords[$this->language]['but']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * Returns all step keywords (Given, When, Then, And, But). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 | 165 |  |     public function getStepKeywords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 165 |  |         if (!isset($this->keywordString[$this->language])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 | 165 |  |             $keywords = array_merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 | 165 |  |                 explode('|', $this->getGivenKeywords()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 165 |  |                 explode('|', $this->getWhenKeywords()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 | 165 |  |                 explode('|', $this->getThenKeywords()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 165 |  |                 explode('|', $this->getAndKeywords()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 | 165 |  |                 explode('|', $this->getButKeywords()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 165 |  |             usort($keywords, function ($keyword1, $keyword2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 | 165 |  |                 return mb_strlen($keyword2, 'utf8') - mb_strlen($keyword1, 'utf8'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 | 165 |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             $this->keywordString[$this->language] = implode('|', $keywords); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         return $this->keywordString[$this->language]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 210 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 211 |  |  |  |