Пример #1
0
 /**
  * Compile the attribute value into it's PHP code.
  * 
  * @param ExpressCompiler $compiler
  * @param integer $flags Raw mode is used when the element is going to be morphed from a TagBuilder.
  */
 public function compile(ExpressCompiler $compiler, $flags = 0)
 {
     try {
         if ($flags & self::FLAG_RAW) {
             if (empty($this->childNodes)) {
                 $compiler->write("''");
             } else {
                 $compiler->write('(');
                 foreach ($this->childNodes as $i => $node) {
                     if ($i > 0) {
                         $compiler->write(' . ');
                     }
                     $node->compile($compiler, self::FLAG_RAW);
                 }
                 $compiler->write(')');
             }
         } else {
             foreach ($this->childNodes as $node) {
                 $node->compile($compiler);
             }
         }
     } catch (ExpressViewException $e) {
         throw $e;
     } catch (\Exception $e) {
         throw new ExpressViewException(sprintf('Unable to compile attribute "%s"', $this->name), $compiler->getResource(), $this->line, $e);
     }
 }
Пример #2
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);
     }
 }
Пример #3
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);
     }
 }
Пример #4
0
 public function compile(ExpressCompiler $compiler, $flags = 0)
 {
     try {
         $id = $compiler->nextId();
         $compiler->write("\t\ttry {\n");
         $compiler->write("\t\t\$dec{$id} = new DecoratedTemplate(\$this->factory, \$this->renderer);\n");
         $compiler->write("\t\t\$dec" . $id . "->bindOuterContext(\$this->context, \$this->exp);\n");
         $compiler->write("\t\t\$dec" . $id . "->setResource(\$this->resolveResource(");
         $view = '';
         foreach ($this->view as $i => $node) {
             if ($i != 0) {
                 $compiler->write(' . ');
             }
             $node->compile($compiler, self::FLAG_RAW);
             if ($node instanceof TextNode) {
                 $view .= $node->getText();
             } elseif ($node instanceof ExpressionNode) {
                 $view .= $node->getExpression();
             }
         }
         $compiler->write("));\n");
         $compiler->write("\t\t\$dec" . $id . "->setBlocks([");
         $num = 0;
         foreach ($this->childNodes as $node) {
             if (!$node instanceof BlockNode) {
                 if ($node instanceof TextNode || trim($node->getText()) == '') {
                     continue;
                 }
                 throw new \InvalidArgumentException('Decorators must only habe child elements of type "block"');
             }
             if ($num++ != 0) {
                 $compiler->write(",\n");
             }
             $compiler->write(var_export($node->getName(), true) . ' => function(OutputBuffer $out) { ' . "\n");
             foreach ($node->getChildNodes() as $childNode) {
                 $childNode->compile($compiler);
             }
             $compiler->write("\t\t}");
         }
         $compiler->write("]);\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(sprintf('Unable to create decorator for view "%s"', $view), true));
         $compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
         $compiler->write("\t\t}\n");
         if (!($flags & self::FLAG_NO_OUTPUT)) {
             $compiler->write("\t\ttry {\n");
             $compiler->write("\t\t\$dec" . $id . "->__invoke(\$out);\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(sprintf('Unable to invoke decorator for view "%s"', $view), true));
             $compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
             $compiler->write("\t\t}\n");
         }
         return '$dec' . $id;
     } catch (ExpressViewException $e) {
         throw $e;
     } catch (\Exception $e) {
         throw new ExpressViewException('Unable to compile decorator node', $compiler->getResource(), $this->line, $e);
     }
 }