Ejemplo n.º 1
0
 public function enterInsert(Insert $node)
 {
     if ($this->isEchoMode()) {
         $escaping = $node->getEscaping()->isEnabled();
         if (true === $escaping) {
             $fmt = '{{ (%s)|escape }}';
         } elseif (false === $escaping) {
             $fmt = '{{ (%s)|raw }}';
         } else {
             $fmt = '{{ %s }}';
         }
         $this->addDebugInfos($node);
         $this->raw(sprintf($fmt, $node->getContent()));
     } else {
         $content = $node->getContent();
         if (!preg_match('~^[a-zA-Z0-9_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$~', $content)) {
             $this->raw('(' . $node->getContent() . ')');
         } else {
             $this->raw($node->getContent());
         }
     }
 }
 public function enterInsert(Insert $node)
 {
     $content = $node->getContent();
     $content = $this->trimInlineComments($content);
     if ($this->isEchoMode()) {
         $fmt = '<?php echo %s; ?>';
         if ($node->getEscaping()->isEnabled()) {
             if ($node->getEscaping()->isOnce()) {
                 $fmt = "<?php echo htmlspecialchars(%s,ENT_QUOTES,'%s',false); ?>";
             } else {
                 $fmt = "<?php echo htmlspecialchars(%s,ENT_QUOTES,'%s'); ?>";
             }
         }
         $this->addDebugInfos($node);
         $this->raw(sprintf($fmt, $content, $this->charset));
     } else {
         $content = $node->getContent();
         if (!preg_match('~^\\$?[a-zA-Z0-9_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$~', $content)) {
             $this->raw('(' . $content . ')');
         } else {
             $this->raw($content);
         }
     }
 }
Ejemplo n.º 3
0
 public function enterInsert(Insert $node)
 {
     $content = $node->getContent();
     $escaping = $node->getEscaping();
     if (true === $escaping->isEnabled()) {
         $flag = '&';
         if ($node->getEscaping()->isOnce()) {
             $flag .= '!';
         }
         $content = $flag . $content;
     } elseif (false === $escaping->isEnabled()) {
         $content = '!' . $content;
     }
     $this->raw('insert(' . $content . ')');
 }
Ejemplo n.º 4
0
 protected function parseNestableStatement($buf)
 {
     if ($buf->match('/([&!]?)(==?|~)\\s*/A', $match)) {
         if ($match[2] == '==') {
             $node = $this->parseInterpolatedString($buf, false);
         } else {
             $node = new Insert($match['pos'][0], $buf->getLine());
         }
         if ($match[1] == '&') {
             $node->getEscaping()->setEnabled(true);
         } else {
             if ($match[1] == '!') {
                 $node->getEscaping()->setEnabled(false);
             }
         }
         $buf->skipWs();
         return $node;
     }
     if (null !== ($comment = $this->parseComment($buf))) {
         return $comment;
     }
     $position = array('lineno' => $buf->getLineno(), 'column' => $buf->getColumn());
     if ('\\' === $buf->peekChar()) {
         $buf->eatChar();
     }
     if (strlen(trim($buf->getLine())) > 0) {
         return $this->parseInterpolatedString($buf, false);
     }
 }
Ejemplo n.º 5
0
 protected function parseInsert(Buffer $buf)
 {
     if ($buf->match('/([&!]?)(==?|~)\\s*/A', $match)) {
         if ($match[2] == '==') {
             $node = $this->parseInterpolatedString($buf, false);
         } else {
             $code = $this->getMultilineCode($buf);
             $node = new Insert($match['pos'][0], $code);
         }
         if ($match[1] == '&') {
             $node->getEscaping()->setEnabled(true);
         } elseif ($match[1] == '!') {
             $node->getEscaping()->setEnabled(false);
         }
         $buf->skipWs();
         return $node;
     }
 }