Skip to content

Commit 2f74854

Browse files
author
Yuri Kovsher
committed
MAGETWO-33062: Update dictionary search tool to support \Magento\Framework\Phrase
1 parent 98ed69c commit 2f74854

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

dev/tests/integration/testsuite/Magento/Test/Tools/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollectorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected function setUp()
3838
public function testParse()
3939
{
4040
$file = __DIR__.'/_files/objectsCode.php.txt';
41-
$this->phraseCollector->parse($file, true);
41+
$this->phraseCollector->setIncludeObjects();
42+
$this->phraseCollector->parse($file);
4243
$expectation = [
4344
[
4445
'phrase' => '\'Testing\'',

dev/tests/unit/testsuite/Magento/Tools/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollectorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public function testParse(
9292
$isMatchingClassReturnValues
9393
));
9494

95-
$this->phraseCollector->parse($file, true);
95+
$this->phraseCollector->setIncludeObjects();
96+
$this->phraseCollector->parse($file);
9697
$this->assertEquals($result, $this->phraseCollector->getPhrases());
9798
}
9899

dev/tools/Magento/Tools/I18n/Parser/Adapter/Php.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function __construct(PhraseCollector $phraseCollector)
3434
*/
3535
protected function _parse()
3636
{
37-
$this->_phraseCollector->parse($this->_file, true);
37+
$this->_phraseCollector->setIncludeObjects();
38+
$this->_phraseCollector->parse($this->_file);
3839

3940
foreach ($this->_phraseCollector->getPhrases() as $phrase) {
4041
$this->_addPhrase($phrase['phrase'], $phrase['line']);

dev/tools/Magento/Tools/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollector.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ class PhraseCollector
3131
*/
3232
protected $_file;
3333

34+
/**
35+
* Are the Phrase objects are parsed as well
36+
*
37+
* @var bool
38+
*/
39+
protected $includeObjects = false;
40+
3441
/**
3542
* Construct
3643
*
3744
* @param Tokenizer $tokenizer
45+
* @param bool $includeObjects
3846
*/
39-
public function __construct(Tokenizer $tokenizer)
47+
public function __construct(Tokenizer $tokenizer, $includeObjects = false)
4048
{
4149
$this->_tokenizer = $tokenizer;
50+
$this->includeObjects = $includeObjects;
4251
}
4352

4453
/**
@@ -55,29 +64,27 @@ public function getPhrases()
5564
* Parse given files for phrase
5665
*
5766
* @param string $file
58-
* @param bool $searchObjects
5967
* @return void
6068
*/
61-
public function parse($file, $searchObjects = false)
69+
public function parse($file)
6270
{
6371
$this->_phrases = [];
6472
$this->_file = $file;
6573
$this->_tokenizer->parse($file);
6674
while (!$this->_tokenizer->isEndOfLoop()) {
67-
$this->_extractPhrases($searchObjects);
75+
$this->_extractPhrases();
6876
}
6977
}
7078

7179
/**
7280
* Extract phrases from given tokens. e.g.: __('phrase', ...)
7381
*
74-
* @param bool $searchObjects
7582
* @return void
7683
*/
77-
protected function _extractPhrases($searchObjects)
84+
protected function _extractPhrases()
7885
{
7986
if ($firstToken = $this->_tokenizer->getNextRealToken()) {
80-
if (!$this->extractMethodPhrase($firstToken) && $searchObjects) {
87+
if (!$this->extractMethodPhrase($firstToken) && $this->includeObjects) {
8188
$this->extractObjectPhrase($firstToken);
8289
}
8390
}
@@ -161,4 +168,14 @@ protected function _addPhrase($phrase, $argumentsAmount, $file, $line)
161168
'line' => $line,
162169
];
163170
}
171+
172+
/**
173+
* @param bool $includeObjects
174+
* @return $this
175+
*/
176+
public function setIncludeObjects($includeObjects = true)
177+
{
178+
$this->includeObjects = (bool)$includeObjects;
179+
return $this;
180+
}
164181
}

0 commit comments

Comments
 (0)