示例#1
0
 public function compile(ExpressCompiler $compiler, $flags = 0)
 {
     try {
         $sub = $compiler->createCompiler();
         foreach ($this->childNodes as $node) {
             $node->compile($sub);
         }
         $compiler->writeBlock($this->name, $sub);
     } catch (ExpressViewException $e) {
         throw $e;
     } catch (\Exception $e) {
         throw new ExpressViewException(sprintf('Unable to compile block "%s"', $this->name), $compiler->getResource(), $this->line, $e);
     }
 }
示例#2
0
 /**
  * Compiles the text node into it's PHP code.
  * 
  * @param ExpressCompiler $compiler
  * @param integer $flags Raw mode is used when an element is morphed using a tag builder.
  */
 public function compile(ExpressCompiler $compiler, $flags = 0)
 {
     try {
         if ($flags & self::FLAG_RAW) {
             $compiler->write(var_export($this->text, true));
         } else {
             // Using ENT_COMPAT due to Knockout JS (and others) data binding, this is not risky
             // in Express-parsed attribute values due to the fact that all attribute values
             // are normalized to be quoted using double quotes.
             $compiler->out(htmlspecialchars($this->text, ENT_COMPAT | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8'));
         }
     } catch (ExpressViewException $e) {
         throw $e;
     } catch (\Exception $e) {
         throw new ExpressViewException('Unable to compile text node', $compiler->getResource(), $this->line, $e);
     }
 }
示例#3
0
 /**
  * Compiles an expression into PHP code.
  * 
  * @param ExpressCompiler $compiler
  * @param integer $flags Raw mode is active when an element is morphed from a TagBuilder.
  */
 public function compile(ExpressCompiler $compiler, $flags = 0)
 {
     try {
         if ($flags & self::FLAG_RAW) {
             $compiler->write($this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp'));
         } else {
             $compiler->write("\t\ttry {\n");
             if ($this->stringify) {
                 if ($this->expression->hasPipedFilter('raw')) {
                     $contents = '$out->write(' . $this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp') . ');';
                 } else {
                     $contents = '$out->writeEscaped(' . $this->expression->compile($compiler->getExpressionContextFactory(), false, '$this->exp') . ');';
                 }
             } else {
                 $contents = 'return ' . $this->expression->compile($compiler->getExpressionContextFactory(), false, $this->exp) . ';';
             }
             $compiler->write("\t\t" . $contents . "\n");
             $compiler->write("\t\t} catch(ExpressViewException \$ex) {\n");
             $compiler->write("\t\t\tthrow \$ex;\n");
             $compiler->write("\t\t} catch(\\Exception \$ex) {\n");
             $compiler->write("\t\t\tthrow new ExpressViewException(");
             $compiler->write(var_export('Error during evaluation of expression "' . $this->expression . '"', true));
             $compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
             $compiler->write("\t\t}\n");
         }
     } catch (ExpressViewException $e) {
         throw $e;
     } catch (\Exception $e) {
         throw new ExpressViewException(sprintf('Unable to compile expression "%s"', $this->expression), $compiler->getResource(), $this->line, $e);
     }
 }