function render(View $view, array $arguments) { if (count($arguments) !== 1) { throw new \InvalidArgumentException('Exactly one view must be specified'); } return $view->getVariable($arguments[0])->render(); }
function render(View $view, array $arguments) { if (count($arguments) !== 2) { throw new \InvalidArgumentException('Exactly two arguments must be specified'); } $glue = $arguments[1]; $pieces = $arguments[0]; if (is_string($pieces)) { $pieces = $view->getVariable($pieces); } $renderedPieces = []; foreach ($pieces as $piece) { if ($piece instanceof View) { $renderedPieces[] = $piece->render(); } else { $renderedPieces[] = $piece; } } return join($glue, $renderedPieces); }
function render(View $view, array $arguments) { $flags = []; if (count($arguments) === 2) { if ($arguments[1] !== 'checkbox') { throw new \InvalidArgumentException("Unsupported flag '{$arguments['1']}'"); } $flags[] = $arguments[1]; } elseif (count($arguments) !== 1) { throw new \InvalidArgumentException('Exactly one variable name must be specified,' . 'with one optional flag'); } $inputName = $arguments[0]; if (!in_array($inputName, $this->registeredInputs)) { throw new \Exception("InputDirective {$inputName} have not been registered"); } if (isset($_POST[$inputName])) { if (in_array('checkbox', $flags) && $_POST[$inputName] === 'on') { return 'name="' . $inputName . '" checked'; } return 'name="' . $inputName . '" value="' . $view->getVariable($inputName) . '"'; } return 'name="' . $inputName . '"'; }
/** * @param View $view The View this directive is rendered in. * @param array $arguments All arguments specified in the template. * @throws \InvalidArgumentException If more or less than one argument specified. * @return string Return a rendered version of this directive. */ function render(View $view, array $arguments) { $this->view = $view; $this->expression = join(' ', $arguments); $this->calculate(self::PRIORITY_MATH); $this->calculate(self::MATH); $this->check(self::BOOLEAN_EXPRESSION); $this->check(self::LOGIC_EXPRESSION); if (preg_match(self::NEGATION, $this->expression, $match)) { $result = !$view->getVariable($match[1]) ? 1 : 0; $this->expression = str_replace($match[0], $result, $this->expression); } $this->expression = $view->getVariable($this->expression); $this->expression = $this->htmlEscape($this->expression); return $this->expression; }