/** * Extract phrases from given tokens. e.g.: __('phrase', ...) * * @return void */ protected function _extractPhrases() { $phraseStartToken = $this->_tokenizer->getNextToken(); if ($phraseStartToken->isEqualFunction('__') && $this->_tokenizer->getNextToken()->isOpenBrace()) { $arguments = $this->_tokenizer->getFunctionArgumentsTokens(); $phrase = $this->_collectPhrase(array_shift($arguments)); if (null !== $phrase) { $this->_addPhrase($phrase, count($arguments), $this->_file, $phraseStartToken->getLine()); } } }
/** * @param Token $firstToken * @return bool */ protected function extractObjectPhrase(Token $firstToken) { if ($firstToken->isNew() && $this->_tokenizer->isMatchingClass('Phrase')) { $arguments = $this->_tokenizer->getFunctionArgumentsTokens(); $phrase = $this->_collectPhrase(array_shift($arguments)); if (null !== $phrase) { $this->_addPhrase($phrase, count($arguments), $this->_file, $firstToken->getLine()); return true; } } return false; }
/** * @covers \Magento\Tools\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector::parse * * @param string $file * @param array $isEndOfLoopReturnValues * @param array $getNextRealTokenReturnValues * @param array $getFunctionArgumentsTokensReturnValues * @param array $isMatchingClassReturnValues * @param array $result * @dataProvider testParseDataProvider */ public function testParse($file, array $isEndOfLoopReturnValues, array $getNextRealTokenReturnValues, array $getFunctionArgumentsTokensReturnValues, array $isMatchingClassReturnValues, array $result) { $matchingClass = 'Phrase'; $this->tokenizerMock->expects($this->once())->method('parse')->with($file); $this->tokenizerMock->expects($this->atLeastOnce())->method('isEndOfLoop')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $isEndOfLoopReturnValues)); $this->tokenizerMock->expects($this->any())->method('getNextRealToken')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getNextRealTokenReturnValues)); $this->tokenizerMock->expects($this->any())->method('getFunctionArgumentsTokens')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getFunctionArgumentsTokensReturnValues)); $this->tokenizerMock->expects($this->any())->method('isMatchingClass')->with($matchingClass)->will(call_user_func_array([$this, 'onConsecutiveCalls'], $isMatchingClassReturnValues)); $this->phraseCollector->setIncludeObjects(); $this->phraseCollector->parse($file); $this->assertEquals($result, $this->phraseCollector->getPhrases()); }
protected function parseFile() { $file = __DIR__ . '/_files/objectsCode.php.txt'; $this->tokenizer->parse($file); }