コード例 #1
0
ファイル: TagMapper.php プロジェクト: noikiy/PHPStamp
 private function parseFunction(Lexer $lexer, $delimiter = Lexer::T_COLON, $return = Lexer::T_CLOSE_BRACKET)
 {
     $function = null;
     $arguments = array();
     $expected = Lexer::T_STRING;
     $optional = null;
     while ($lexer->moveNext()) {
         $token = $lexer->lookahead;
         if ($token['type'] === $delimiter || $token['type'] === $return) {
             return array('function' => $function, 'arguments' => $arguments);
         }
         if ($token['type'] !== $expected && $token['type'] !== $optional) {
             var_dump($token);
             throw new ProcessorException('Unexpected token' . ', expected ' . $lexer->getLiteral($expected) . ', got ' . $lexer->getLiteral($token['type']));
         }
         $optional = null;
         // Reset as we passed through
         switch ($token['type']) {
             case Lexer::T_STRING:
                 // Function id
                 if ($function === null) {
                     $function = $token['value'];
                     $expected = Lexer::T_OPEN_PARENTHESIS;
                     $optional = null;
                     break;
                 }
                 // Fall for arguments parsing
                 $arguments[] = $token['value'];
                 $expected = Lexer::T_CLOSE_PARENTHESIS;
                 $optional = Lexer::T_COMMA;
                 break;
             case Lexer::T_COMMA:
                 $expected = Lexer::T_STRING;
                 break;
             case Lexer::T_OPEN_PARENTHESIS:
                 $expected = Lexer::T_CLOSE_PARENTHESIS;
                 $optional = Lexer::T_STRING;
                 break;
             case Lexer::T_CLOSE_PARENTHESIS:
                 $expected = $return;
                 $optional = $delimiter;
                 break;
         }
     }
     return array('function' => $function, 'arguments' => $arguments);
     // IDE fix
 }
コード例 #2
0
ファイル: Templator.php プロジェクト: noikiy/PHPStamp
 private function searchAndReplace(\DOMNodeList $nodeList, DocumentInterface $document)
 {
     $lexer = new Lexer($this->brackets);
     $mapper = new TagMapper();
     /** @var $node \DOMElement */
     foreach ($nodeList as $node) {
         $decodedValue = utf8_decode($node->nodeValue);
         $lexer->setInput($decodedValue);
         while ($tag = $mapper->parse($lexer)) {
             foreach ($tag->getFunctions() as $function) {
                 $expression = $document->getExpression($function['function'], $tag);
                 $expression->execute($function['arguments'], $node);
             }
             // insert simple value-of
             if ($tag->hasFunctions() === false) {
                 $absolutePath = '/' . Processor::VALUE_NODE . '/' . $tag->getXmlPath();
                 Processor::insertTemplateLogic($tag->getTextContent(), $absolutePath, $node);
             }
         }
     }
 }