[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Bridge\Twig\Node; 13 14 use Twig\Compiler; 15 use Twig\Node\Expression\ArrayExpression; 16 use Twig\Node\Expression\ConstantExpression; 17 use Twig\Node\Expression\FunctionExpression; 18 19 /** 20 * @author Bernhard Schussek <bschussek@gmail.com> 21 */ 22 class SearchAndRenderBlockNode extends FunctionExpression 23 { 24 public function compile(Compiler $compiler) 25 { 26 $compiler->addDebugInfo($this); 27 $compiler->raw('$this->env->getExtension(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock('); 28 29 preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches); 30 31 $label = null; 32 $arguments = iterator_to_array($this->getNode('arguments')); 33 $blockNameSuffix = $matches[1]; 34 35 if (isset($arguments[0])) { 36 $compiler->subcompile($arguments[0]); 37 $compiler->raw(', \''.$blockNameSuffix.'\''); 38 39 if (isset($arguments[1])) { 40 if ('label' === $blockNameSuffix) { 41 // The "label" function expects the label in the second and 42 // the variables in the third argument 43 $label = $arguments[1]; 44 $variables = isset($arguments[2]) ? $arguments[2] : null; 45 $lineno = $label->getTemplateLine(); 46 47 if ($label instanceof ConstantExpression) { 48 // If the label argument is given as a constant, we can either 49 // strip it away if it is empty, or integrate it into the array 50 // of variables at compile time. 51 $labelIsExpression = false; 52 53 // Only insert the label into the array if it is not empty 54 if (!twig_test_empty($label->getAttribute('value'))) { 55 $originalVariables = $variables; 56 $variables = new ArrayExpression(array(), $lineno); 57 $labelKey = new ConstantExpression('label', $lineno); 58 59 if (null !== $originalVariables) { 60 foreach ($originalVariables->getKeyValuePairs() as $pair) { 61 // Don't copy the original label attribute over if it exists 62 if ((string) $labelKey !== (string) $pair['key']) { 63 $variables->addElement($pair['value'], $pair['key']); 64 } 65 } 66 } 67 68 // Insert the label argument into the array 69 $variables->addElement($label, $labelKey); 70 } 71 } else { 72 // The label argument is not a constant, but some kind of 73 // expression. This expression needs to be evaluated at runtime. 74 // Depending on the result (whether it is null or not), the 75 // label in the arguments should take precedence over the label 76 // in the attributes or not. 77 $labelIsExpression = true; 78 } 79 } else { 80 // All other functions than "label" expect the variables 81 // in the second argument 82 $label = null; 83 $variables = $arguments[1]; 84 $labelIsExpression = false; 85 } 86 87 if (null !== $variables || $labelIsExpression) { 88 $compiler->raw(', '); 89 90 if (null !== $variables) { 91 $compiler->subcompile($variables); 92 } 93 94 if ($labelIsExpression) { 95 if (null !== $variables) { 96 $compiler->raw(' + '); 97 } 98 99 // Check at runtime whether the label is empty. 100 // If not, add it to the array at runtime. 101 $compiler->raw('(twig_test_empty($_label_ = '); 102 $compiler->subcompile($label); 103 $compiler->raw(') ? array() : array("label" => $_label_))'); 104 } 105 } 106 } 107 } 108 109 $compiler->raw(')'); 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |