當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Twig_Node_Expression_Array類代碼示例

本文整理匯總了PHP中Twig_Node_Expression_Array的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_Node_Expression_Array類的具體用法?PHP Twig_Node_Expression_Array怎麽用?PHP Twig_Node_Expression_Array使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Twig_Node_Expression_Array類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
 {
     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);
     if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
         foreach ($matches[1] as $var) {
             $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
             if (!$vars->hasElement($key)) {
                 $vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
             }
         }
     } else {
         $current = array();
         foreach ($vars as $name => $var) {
             $current[$name] = true;
         }
         foreach ($matches[1] as $var) {
             if (!isset($current['%' . $var . '%'])) {
                 $vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
             }
         }
     }
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
開發者ID:miguelibero,項目名稱:meinhof,代碼行數:30,代碼來源:TransNode.php

示例2: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $resources = new \Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
     do {
         $resources->addElement($this->parser->getExpressionParser()->parseExpression());
     } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new GitThemeNode($resources, $lineno, $this->getTag());
 }
開發者ID:gitonomy,項目名稱:git-bundle,代碼行數:11,代碼來源:GitThemeTokenParser.php

示例3: valueNode

 public function valueNode()
 {
     // date value (either a DateTime object, or null)
     $valueNode = parent::valueNode();
     // format('Y-m-d') method call on date object
     $args = new \Twig_Node_Expression_Array([], $this->lineno);
     $args->addElement(new \Twig_Node_Expression_Constant('j M, Y', $this->lineno));
     $formatNode = new \Twig_Node_Expression_MethodCall($valueNode, 'format', $args, $this->lineno);
     // conditional to check for a null value
     $conditionalNode = new \Twig_Node_Expression_Conditional($valueNode, $formatNode, $valueNode, $this->lineno);
     return $conditionalNode;
 }
開發者ID:fierce,項目名稱:fierce,代碼行數:12,代碼來源:DateFieldNode.php

示例4: convertToViewArguments

 protected function convertToViewArguments(\Twig_Node_Expression_Array $array)
 {
     $arguments = array();
     foreach (array_chunk($array->getIterator()->getArrayCopy(), 2) as $pair) {
         if (count($pair) == 2) {
             $key = $pair[0]->getAttribute('value');
             $value = $pair[1]->getAttribute('value');
             // @todo support for multiple types
             $arguments[$key] = $value;
         }
     }
     return $arguments;
 }
開發者ID:LeonB,項目名稱:site,代碼行數:13,代碼來源:twig_setcontent.php

示例5: escapeContextVariables

 /**
  * @param  string                      $msg
  * @param  \Twig_Node_Expression_Array $vars
  * @param  int                         $lineno
  * @return \Twig_Node_Expression_Array
  */
 protected function escapeContextVariables($msg, $vars, $lineno)
 {
     preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         $key = new \Twig_Node_Expression_Constant('%' . $var . '%', $lineno);
         if (!$vars->hasElement($key)) {
             $node = new \Twig_Node_Expression_Name($var, $lineno);
             $node = $this->escapeNodeIfNecessary($node, $lineno);
             $vars->addElement($node, $key);
         }
     }
     return $vars;
 }
開發者ID:arthens,項目名稱:safe-translations,代碼行數:19,代碼來源:SafeTransNode.php

示例6: getTests

 public function getTests()
 {
     $tests = array();
     $expr = new Twig_Node_Expression_Name('foo', 1);
     $attr = new Twig_Node_Expression_Constant('bar', 1);
     $args = new Twig_Node_Expression_Array(array(), 1);
     $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1);
     $tests[] = array($node, sprintf('%s%s, "bar", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
     $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
     $tests[] = array($node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
     $args = new Twig_Node_Expression_Array(array(), 1);
     $args->addElement(new Twig_Node_Expression_Name('foo', 1));
     $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
     $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1);
     $tests[] = array($node, sprintf('%s%s, "bar", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));
     return $tests;
 }
開發者ID:rjagadishsingh,項目名稱:Twig,代碼行數:17,代碼來源:GetAttrTest.php

示例7: parse

 /**
  * {@inheritdoc}
  */
 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $stream = $this->parser->getStream();
     $datagrid = $this->parser->getExpressionParser()->parseExpression();
     if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
         $this->parser->getStream()->next();
         $resources = $this->parser->getExpressionParser()->parseExpression();
     } else {
         $resources = new \Twig_Node_Expression_Array([], $stream->getCurrent()->getLine());
         do {
             $resources->addElement($this->parser->getExpressionParser()->parseExpression());
         } while (!$stream->test(\Twig_Token::BLOCK_END_TYPE));
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return new DatagridThemeNode($datagrid, $resources, $lineno, $this->getTag());
 }
開發者ID:rollerworks,項目名稱:datagrid-twig,代碼行數:20,代碼來源:DatagridThemeTokenParser.php

示例8: enterNode

 /**
  * @param \Twig_NodeInterface $node
  * @param \Twig_Environment $env
  * @return \Twig_NodeInterface
  */
 public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
 {
     if (!$this->enabled) {
         return $node;
     }
     if ($node instanceof \Twig_Node_Expression_Filter && 'desc' === $node->getNode('filter')->getAttribute('value')) {
         $transNode = $node->getNode('node');
         while ($transNode instanceof \Twig_Node_Expression_Filter && 'trans' !== $transNode->getNode('filter')->getAttribute('value') && 'transchoice' !== $transNode->getNode('filter')->getAttribute('value')) {
             $transNode = $transNode->getNode('node');
         }
         if (!$transNode instanceof \Twig_Node_Expression_Filter) {
             throw new RuntimeException(sprintf('The "desc" filter must be applied after a "trans", or "transchoice" filter.'));
         }
         $wrappingNode = $node->getNode('node');
         $testNode = clone $wrappingNode;
         $defaultNode = $node->getNode('arguments')->getNode(0);
         // if the |transchoice filter is used, delegate the call to the TranslationExtension
         // so that we can catch a possible exception when the default translation has not yet
         // been extracted
         if ('transchoice' === $transNode->getNode('filter')->getAttribute('value')) {
             $transchoiceArguments = new \Twig_Node_Expression_Array(array(), $transNode->getLine());
             $transchoiceArguments->addElement($wrappingNode->getNode('node'));
             $transchoiceArguments->addElement($defaultNode);
             foreach ($wrappingNode->getNode('arguments') as $arg) {
                 $transchoiceArguments->addElement($arg);
             }
             $transchoiceNode = new \Twig_Node_Expression_MethodCall(new \Twig_Node_Expression_ExtensionReference('jms_translation', $transNode->getLine()), 'transchoiceWithDefault', $transchoiceArguments, $transNode->getLine());
             $node->setNode('node', $transchoiceNode);
             return $node;
         }
         // if the |trans filter has replacements parameters
         // (e.g. |trans({'%foo%': 'bar'}))
         if ($wrappingNode->getNode('arguments')->hasNode(0)) {
             $lineno = $wrappingNode->getLine();
             // remove the replacements from the test node
             $testNode->setNode('arguments', clone $testNode->getNode('arguments'));
             $testNode->getNode('arguments')->setNode(0, new \Twig_Node_Expression_Array(array(), $lineno));
             // wrap the default node in a |replace filter
             $defaultNode = new \Twig_Node_Expression_Filter(clone $node->getNode('arguments')->getNode(0), new \Twig_Node_Expression_Constant('replace', $lineno), new \Twig_Node(array(clone $wrappingNode->getNode('arguments')->getNode(0))), $lineno);
         }
         $condition = new \Twig_Node_Expression_Conditional(new \Twig_Node_Expression_Binary_Equal($testNode, $transNode->getNode('node'), $wrappingNode->getLine()), $defaultNode, clone $wrappingNode, $wrappingNode->getLine());
         $node->setNode('node', $condition);
     }
     return $node;
 }
開發者ID:clytemnestra,項目名稱:JMSTranslationBundle,代碼行數:50,代碼來源:DefaultApplyingNodeVisitor.php

示例9: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
 {
     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)) {
             $vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
         }
     }
     return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:18,代碼來源:TransNode.php

示例10: parseArguments

 /**
  * @param \Twig_Token $token
  * @return array
  */
 protected function parseArguments(\Twig_Token $token)
 {
     $stream = $this->parser->getStream();
     $location = null;
     if ($stream->nextIf(\Twig_Token::OPERATOR_TYPE, 'in')) {
         $location = $this->parser->getExpressionParser()->parseExpression();
     } else {
         $lineno = $token->getLine();
         $location = new \Twig_Node_Expression_Constant('head', $lineno);
     }
     if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
         $variables = $this->parser->getExpressionParser()->parseExpression();
     } else {
         $lineno = $token->getLine();
         $variables = new \Twig_Node_Expression_Array([], $lineno);
         $variables->setAttribute('priority', 0);
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     return [$location, $variables];
 }
開發者ID:ericssonm,項目名稱:JusCuzCustoms,代碼行數:24,代碼來源:TokenParserAssets.php

示例11: compileString

 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
 {
     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);
     }
     $current = array();
     foreach ($vars as $name => $var) {
         $current[$name] = true;
     }
     preg_match_all('/\\%([^\\%]+)\\%/', $msg, $matches);
     foreach ($matches[1] as $var) {
         if (!isset($current['%' . $var . '%'])) {
             $vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
         }
     }
     return array(new \Twig_Node_Expression_Constant(trim($msg), $body->getLine()), $vars);
 }
開發者ID:nickaggarwal,項目名稱:sample-symfony2,代碼行數:21,代碼來源:TransNode.php

示例12: parse

 public function parse(\Twig_Token $token)
 {
     $lineno = $token->getLine();
     $arguments = new \Twig_Node_Expression_Array(array(), $lineno);
     $wherearguments = null;
     // name - the new variable with the results
     $name = $this->parser->getStream()->expect(\Twig_Token::NAME_TYPE)->getValue();
     $this->parser->getStream()->expect(\Twig_Token::OPERATOR_TYPE, '=');
     // contenttype, or simple expression to content.
     $contenttype = $this->parser->getExpressionParser()->parseExpression();
     $counter = 0;
     do {
         // where parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'where')) {
             $this->parser->getStream()->next();
             $wherearguments = $this->parser->getExpressionParser()->parseExpression();
         }
         // limit parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'limit')) {
             $this->parser->getStream()->next();
             $limit = $this->parser->getExpressionParser()->parseExpression();
             $arguments->addElement($limit, new \Twig_Node_Expression_Constant('limit', $lineno));
         }
         // order / orderby parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'order') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'orderby')) {
             $this->parser->getStream()->next();
             $order = $this->parser->getExpressionParser()->parseExpression();
             $arguments->addElement($order, new \Twig_Node_Expression_Constant('order', $lineno));
         }
         // paging / allowpaging parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'paging') || $this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'allowpaging')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(true, $lineno), new \Twig_Node_Expression_Constant('paging', $lineno));
         }
         // printquery parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'printquery')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(true, $lineno), new \Twig_Node_Expression_Constant('printquery', $lineno));
         }
         // returnsingle parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'returnsingle')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(true, $lineno), new \Twig_Node_Expression_Constant('returnsingle', $lineno));
         }
         // nohydrate parameter
         if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'nohydrate')) {
             $this->parser->getStream()->next();
             $arguments->addElement(new \Twig_Node_Expression_Constant(false, $lineno), new \Twig_Node_Expression_Constant('hydrate', $lineno));
         }
         // Make sure we don't get stuck in a loop, if a token can't be parsed.
         $counter++;
     } while (!$this->parser->getStream()->test(\Twig_Token::BLOCK_END_TYPE) && $counter < 10);
     $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
     return new SetcontentNode($name, $contenttype, $arguments, $wherearguments, $lineno, $this->getTag());
 }
開發者ID:aleksabp,項目名稱:bolt,代碼行數:55,代碼來源:SetcontentTokenParser.php

示例13: compileString

 protected function compileString(\Twig_NodeInterface $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:neteasy-work,項目名稱:hkgbf_crm,代碼行數:24,代碼來源:TransNode.php

示例14: parseSubscriptExpression

 public function parseSubscriptExpression($node)
 {
     $stream = $this->parser->getStream();
     $token = $stream->next();
     $lineno = $token->getLine();
     $arguments = new Twig_Node_Expression_Array(array(), $lineno);
     $type = Twig_Template::ANY_CALL;
     if ($token->getValue() == '.') {
         $token = $stream->next();
         if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE || $token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) {
             $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
                 $type = Twig_TemplateInterface::METHOD_CALL;
                 foreach ($this->parseArguments() as $n) {
                     $arguments->addElement($n);
                 }
             }
         } else {
             throw new Twig_Error_Syntax('Expected name or number', $lineno, $this->parser->getFilename());
         }
         if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
             if (!$arg instanceof Twig_Node_Expression_Constant) {
                 throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s")', $node->getAttribute('name')), $token->getLine(), $this->parser->getFilename());
             }
             $node = new Twig_Node_Expression_MethodCall($node, 'get' . $arg->getAttribute('value'), $arguments, $lineno);
             $node->setAttribute('safe', true);
             return $node;
         }
     } else {
         $type = Twig_Template::ARRAY_CALL;
         // slice?
         $slice = false;
         if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) {
             $slice = true;
             $arg = new Twig_Node_Expression_Constant(0, $token->getLine());
         } else {
             $arg = $this->parseExpression();
         }
         if ($stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) {
             $slice = true;
         }
         if ($slice) {
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
                 $length = new Twig_Node_Expression_Constant(null, $token->getLine());
             } else {
                 $length = $this->parseExpression();
             }
             $class = $this->getFilterNodeClass('slice', $token->getLine());
             $arguments = new Twig_Node(array($arg, $length));
             $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine());
             $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
             return $filter;
         }
         $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
     }
     return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno);
 }
開發者ID:dev-lav,項目名稱:htdocs,代碼行數:57,代碼來源:ExpressionParser.php

示例15: parseSubscriptExpression

 public function parseSubscriptExpression($node)
 {
     $stream = $this->parser->getStream();
     $token = $stream->next();
     $lineno = $token->getLine();
     $arguments = new Twig_Node_Expression_Array(array(), $lineno);
     $type = Twig_TemplateInterface::ANY_CALL;
     if ($token->getValue() == '.') {
         $token = $stream->next();
         if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE || $token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue())) {
             $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
                 $type = Twig_TemplateInterface::METHOD_CALL;
                 foreach ($this->parseArguments() as $n) {
                     $arguments->addElement($n);
                 }
             }
         } else {
             throw new Twig_Error_Syntax('Expected name or number', $lineno);
         }
     } else {
         $type = Twig_TemplateInterface::ARRAY_CALL;
         $arg = $this->parseExpression();
         // slice?
         if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) {
             $stream->next();
             if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
                 $length = new Twig_Node_Expression_Constant(null, $token->getLine());
             } else {
                 $length = $this->parseExpression();
             }
             $class = $this->getFilterNodeClass('slice');
             $arguments = new Twig_Node(array($arg, $length));
             $filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine());
             $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
             return $filter;
         }
         $stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
     }
     return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno);
 }
開發者ID:Zyko0,項目名稱:Baikal,代碼行數:41,代碼來源:ExpressionParser.php


注:本文中的Twig_Node_Expression_Array類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。