当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Node::getLine方法代码示例

本文整理汇总了PHP中Twig_Node::getLine方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Node::getLine方法的具体用法?PHP Twig_Node::getLine怎么用?PHP Twig_Node::getLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Node的用法示例。


在下文中一共展示了Twig_Node::getLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 public static function process(\Twig_Node $node, Translations $translations, $file)
 {
     $fileReference = str_replace(realpath(self::$rootDir . '/../') . '/', "", $file);
     if ($node instanceof TransNode) {
         //Process nodes that {% trans %} blocks
         $body = new \Twig_Node_Expression_Constant($node->getNode('body')->getAttribute('data'), $node->getLine());
         $compiledTranslation = eval('return ' . self::$twig->compile($body) . ';');
         $translations->insert('', $compiledTranslation)->addReference($fileReference, $node->getLine());
     }
     if ($node instanceof \Twig_Node_Expression_Function) {
         //Process nodes that are function expressions
         if ($node->getAttribute('name') == '__') {
             //Check the function name for __()
             foreach ($node->getNode('arguments') as $argument) {
                 //Grab the argument
                 $key = eval('return ' . self::$twig->compile($argument) . ';');
                 $translations->insert('', $key)->addReference($fileReference, $node->getLine());
                 break;
                 //I only needed the first argument in my implementation
             }
         }
     }
     //Recursively loop through the AST
     foreach ($node as $child) {
         if ($child instanceof \Twig_Node) {
             self::process($child, $translations, $file);
         }
     }
 }
开发者ID:mablae,项目名称:gettext-bundle,代码行数:29,代码来源:SymfonyTwig.php

示例2: loadNode

 private function loadNode(Node $node, $resource)
 {
     $assets = array();
     if ($node instanceof ExpressionFunction) {
         $name = $node->getAttribute('name');
         if ($name === $this->functionName) {
             $arguments = iterator_to_array($node->getNode('arguments'));
             if (!is_array($arguments)) {
                 throw new ResourceParsingException('arguments is not an array');
             }
             if (count($arguments) !== 1 && count($arguments) !== 2) {
                 throw new ResourceParsingException(sprintf('Expected exactly one or two arguments passed to function %s in %s at line %s', $this->functionName, $resource, $node->getLine()));
             }
             if (!$arguments[0] instanceof ConstantFunction) {
                 throw new ResourceParsingException(sprintf('Argument passed to function %s must be text node to parse without context. File %s, line %s', $this->functionName, $resource, $node->getLine()));
             }
             $assets[] = $arguments[0]->getAttribute('value');
             return $assets;
         }
     }
     foreach ($node as $child) {
         if ($child instanceof Node) {
             $assets = array_merge($assets, $this->loadNode($child, $resource));
         }
     }
     return $assets;
 }
开发者ID:mariusbalcytis,项目名称:webpack-bundle,代码行数:27,代码来源:TwigAssetProvider.php

示例3: __construct

 public function __construct(Twig_Node $node, Twig_Node_Expression_Constant $filterName, Twig_Node $arguments, $lineno, $tag = null)
 {
     $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getLine()), $arguments, $node->getLine());
     if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
         $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getLine());
         $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getLine());
         $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getLine());
     } else {
         $node = $default;
     }
     parent::__construct($node, $filterName, $arguments, $lineno, $tag);
 }
开发者ID:PieterSwitten,项目名称:webandmobile,代码行数:12,代码来源:Default.php

示例4: enterNode

 /**
  * Called before child nodes are visited.
  *
  * @param Twig_Node        $node The node to visit
  * @param Twig_Environment $env  The Twig environment instance
  *
  * @return Twig_Node The modified node
  */
 public function enterNode(Twig_Node $node, Twig_Environment $env)
 {
     if ($node instanceof Twig_Node_Module) {
         $this->inAModule = true;
         $this->tags = array();
         $this->filters = array();
         $this->functions = array();
         return $node;
     } elseif ($this->inAModule) {
         // look for tags
         if ($node->getNodeTag() && !isset($this->tags[$node->getNodeTag()])) {
             $this->tags[$node->getNodeTag()] = $node;
         }
         // look for filters
         if ($node instanceof Twig_Node_Expression_Filter && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) {
             $this->filters[$node->getNode('filter')->getAttribute('value')] = $node;
         }
         // look for functions
         if ($node instanceof Twig_Node_Expression_Function && !isset($this->functions[$node->getAttribute('name')])) {
             $this->functions[$node->getAttribute('name')] = $node;
         }
         // wrap print to check __toString() calls
         if ($node instanceof Twig_Node_Print) {
             return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
         }
     }
     return $node;
 }
开发者ID:rjagadishsingh,项目名称:Twig,代码行数:36,代码来源:Sandbox.php

示例5: applyFilters

 protected function applyFilters(Twig_Node $node)
 {
     if (false === ($filters = $this->getCurrentFilters())) {
         return $node;
     }
     if ($node instanceof Twig_Node_Text) {
         $expression = new Twig_Node_Expression_Constant($node->getData(), $node->getLine());
     } else {
         $expression = $node->getExpression();
     }
     // filters
     if ($expression instanceof Twig_Node_Expression_Filter) {
         $expression->appendFilters($filters);
         return $node;
     } else {
         return new Twig_Node_Print(new Twig_Node_Expression_Filter($expression, $filters, $node->getLine()), $node->getLine());
     }
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:18,代码来源:Filter.php

示例6: compileString

 protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
 {
     // Extract the message to be translated, or return if it doesn't need translations
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return array($body, $vars);
     }
     // Escape variable passed using 'with'
     // {% safetrans with {...} %}{% endsafetrans %}
     $vars = $this->escapeWithVariables($vars, $body->getLine());
     // Escape variables that needs to be read from $context
     // {% safetrans %}...{% endsafetrans %}
     $vars = $this->escapeContextVariables($msg, $vars, $body->getLine());
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
开发者ID:arthens,项目名称:safe-translations,代码行数:18,代码来源:SafeTransNode.php

示例7: compileString

 protected function compileString(\Twig_Node $body)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return $body;
     }
     return new \Twig_Node_Expression_Constant(trim($msg), $body->getLine());
 }
开发者ID:hexmedia,项目名称:content-bundle,代码行数:11,代码来源:AreaNode.php

示例8: escapeNode

 protected function escapeNode(Twig_Node $node, Twig_Environment $env, $type)
 {
     if (false === $type) {
         return $node;
     }
     $expression = $node instanceof Twig_Node_Print ? $node->getExpression() : $node;
     if ($expression instanceof Twig_Node_Expression_Filter) {
         // don't escape if the primary node of the filter is not a variable
         $nodes = $expression->getNodes();
         if (!$nodes[0] instanceof Twig_Node_Expression_Name) {
             return $node;
         }
         // don't escape if there is already an "escaper" in the filter chain
         $filterMap = $env->getFilters();
         foreach ($expression->getFilters() as $filter) {
             if (isset($filterMap[$filter[0]]) && $filterMap[$filter[0]]->isEscaper()) {
                 return $node;
             }
         }
     } elseif (!$expression instanceof Twig_Node_Expression_GetAttr && !$expression instanceof Twig_Node_Expression_Name) {
         // don't escape if the node is not a variable
         return $node;
     }
     // escape
     if ($expression instanceof Twig_Node_Expression_Filter) {
         // escape all variables in filters arguments
         $filters = $expression->getFilters();
         foreach ($filters as $i => $filter) {
             foreach ($filter[1] as $j => $argument) {
                 $filters[$i][1][$j] = $this->escapeNode($argument, $env, $type);
             }
         }
         $expression->setFilters($filters);
         $expression->prependFilter($this->getEscaperFilter($type));
         return $node;
     } elseif ($node instanceof Twig_Node_Print) {
         return new Twig_Node_Print(new Twig_Node_Expression_Filter($expression, array($this->getEscaperFilter($type)), $node->getLine()), $node->getLine());
     } else {
         return new Twig_Node_Expression_Filter($node, array($this->getEscaperFilter($type)), $node->getLine());
     }
 }
开发者ID:jstanden,项目名称:devblocks,代码行数:41,代码来源:Escaper.php

示例9: doEnterNode

 /**
  * {@inheritdoc}
  */
 protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
 {
     if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
         $this->scope = $this->scope->enter();
     }
     if ($node instanceof TransDefaultDomainNode) {
         if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) {
             $this->scope->set('domain', $node->getNode('expr'));
             return $node;
         } else {
             $var = $env->getParser()->getVarName();
             $name = new \Twig_Node_Expression_AssignName($var, $node->getLine());
             $this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getLine()));
             return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getLine());
         }
     }
     if (!$this->scope->has('domain')) {
         return $node;
     }
     if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
         $arguments = $node->getNode('arguments');
         $ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
         if ($this->isNamedArguments($arguments)) {
             if (!$arguments->hasNode('domain') && !$arguments->hasNode($ind)) {
                 $arguments->setNode('domain', $this->scope->get('domain'));
             }
         } else {
             if (!$arguments->hasNode($ind)) {
                 if (!$arguments->hasNode($ind - 1)) {
                     $arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
                 }
                 $arguments->setNode($ind, $this->scope->get('domain'));
             }
         }
     } elseif ($node instanceof TransNode) {
         if (!$node->hasNode('domain')) {
             $node->setNode('domain', $this->scope->get('domain'));
         }
     }
     return $node;
 }
开发者ID:ayoah,项目名称:symfony,代码行数:44,代码来源:TranslationDefaultDomainNodeVisitor.php

示例10: compileString

 protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
 {
     if ($body instanceof \Twig_Node_Expression_Constant) {
         $msg = $body->getAttribute('value');
     } elseif ($body instanceof \Twig_Node_Text) {
         $msg = $body->getAttribute('data');
     } else {
         return array($body, $vars);
     }
     preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
         if (!$vars->hasElement($key)) {
             if ('count' === $var && null !== $this->getNode('count')) {
                 $vars->addElement($this->getNode('count'), $key);
             } else {
                 $varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
                 $varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
                 $vars->addElement($varExpr, $key);
             }
         }
     }
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:24,代码来源:TransNode.php

示例11: getEscaperFilter

 private function getEscaperFilter($type, Twig_Node $node)
 {
     $line = $node->getLine();
     $name = new Twig_Node_Expression_Constant('escape', $line);
     $args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)));
     return new Twig_Node_Expression_Filter($node, $name, $args, $line);
 }
开发者ID:vgrish,项目名称:twiggy,代码行数:7,代码来源:Escaper.php

示例12: __construct

 public function __construct(Twig_Node $left, Twig_Node $right, $lineno)
 {
     $test = new Twig_Node_Expression_Binary_And(new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getLine()), new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getLine()), $left->getLine()), $left->getLine());
     parent::__construct($test, $left, $right, $lineno);
 }
开发者ID:vgrish,项目名称:twiggy,代码行数:5,代码来源:NullCoalesce.php

示例13: checkLoopUsageBody

 private function checkLoopUsageBody(Twig_TokenStream $stream, Twig_Node $node)
 {
     if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
         $attribute = $node->getNode('attribute');
         if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) {
             throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename());
         }
     }
     // should check for parent.loop.XXX usage
     if ($node instanceof Twig_Node_For) {
         return;
     }
     foreach ($node as $n) {
         if (!$n) {
             continue;
         }
         $this->checkLoopUsageBody($stream, $n);
     }
 }
开发者ID:dunglas,项目名称:Twig,代码行数:19,代码来源:For.php

示例14: addDebugInfo

 /**
  * Adds debugging information.
  *
  * @param Twig_Node $node The related twig node
  *
  * @return Twig_Compiler The current compiler instance
  */
 public function addDebugInfo(Twig_Node $node)
 {
     if ($node->getLine() != $this->lastLine) {
         $this->write(sprintf("// line %d\n", $node->getLine()));
         // when mbstring.func_overload is set to 2
         // mb_substr_count() replaces substr_count()
         // but they have different signatures!
         if ((int) ini_get('mbstring.func_overload') & 2) {
             // this is much slower than the "right" version
             $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n");
         } else {
             $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
         }
         $this->sourceOffset = strlen($this->source);
         $this->debugInfo[$this->sourceLine] = $node->getLine();
         $this->lastLine = $node->getLine();
     }
     return $this;
 }
开发者ID:rafasashi,项目名称:Twig,代码行数:26,代码来源:Compiler.php

示例15: addDebugInfo

 /**
  * Adds debugging information.
  *
  * @param Twig_Node $node The related twig node
  *
  * @return Twig_Compiler The current compiler instance
  */
 public function addDebugInfo(Twig_Node $node)
 {
     if ($node->getLine() != $this->lastLine) {
         $this->lastLine = $node->getLine();
         $this->write("// line {$node->getLine()}\n");
     }
     return $this;
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:15,代码来源:Compiler.php


注:本文中的Twig_Node::getLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。