Abstract Class yii\twig\Template
| Inheritance | yii\twig\Template » Twig_Template |
|---|---|
| Source Code | https://github.com/yiisoft/yii2-twig/blob/master/Template.php |
Template base class
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| displayWithErrorHandling() | yii\twig\Template | |
| getAttribute() | yii\twig\Template |
Method Details
| protected void displayWithErrorHandling ( array $context, array $blocks = array() ) | ||
| $context | ||
| $blocks | ||
protected function displayWithErrorHandling(array $context, array $blocks = array())
{
try {
parent::displayWithErrorHandling($context, $blocks);
} catch (\Error $e) {
$r = new \ReflectionObject($this);
$file = $r->getFileName();
foreach ($e->getTrace() as $trace) {
if (isset($trace['file']) and $trace['file'] == $file) {
$debugInfo = $this->getDebugInfo();
if (isset($trace['line']) && isset($debugInfo[$trace['line']])) {
throw new \Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), $debugInfo[$trace['line']], $this->getSourceContext());
}
}
}
throw $e;
}
}
| protected void getAttribute ( $object, $item, array $arguments = [], $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false ) | ||
| $object | ||
| $item | ||
| $arguments | ||
| $type | ||
| $isDefinedTest | ||
| $ignoreStrictCheck | ||
protected function getAttribute($object, $item, array $arguments = [], $type = \Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
// Twig uses isset() to check if attribute exists which does not work when attribute exists but is null
if ($object instanceof \yii\base\Model) {
if ($type === \Twig_Template::METHOD_CALL) {
if ($this->env->hasExtension('sandbox')) {
$this->env->getExtension('sandbox')->checkMethodAllowed($object, $item);
}
return call_user_func_array([$object, $item], $arguments);
} else {
if ($this->env->hasExtension('sandbox')) {
$this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
}
return $object->$item;
}
}
return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
}