/** * {@inheritdoc} */ public function __construct(ViewManager $views, Compiler $compiler, array $options) { $this->compiler = $compiler; $this->options = $options + $this->options; if ($this->compiler->getNamespace() != ViewProviderInterface::DEFAULT_NAMESPACE) { $this->bundle = $compiler->getNamespace(); } //I18n namespace constructed using view name, view namespace and prefix $this->bundle .= '-' . $this->options['prefix'] . str_replace(['/', '\\'], '-', $compiler->getView()); $this->bundle = trim($this->bundle, '-'); }
/** * Must create instance of TemplaterException using exception instance and context token. Might * clarify exception location in html code. * * @param \Exception $exception * @param array $token * @return TemplaterException */ protected function clarifyException(\Exception $exception, array $token = []) { if (!$exception instanceof TemplaterException) { $exception = new TemplaterException($exception->getMessage(), [], $exception->getCode(), $exception); } elseif (empty($token)) { //We can fetch token from exception itself, thx Node $token = $exception->getToken(); } if (empty($token)) { //Exception location can not be clarified return $exception; } //We now can find file exception got raised $source = $this->compiler->getSource(); //We have to process view source to make sure that it has same state as at moment of error foreach ($this->compiler->getProcessors() as $processor) { if ($processor instanceof self) { //The rest will be handled by TemplateProcessor break; } $source = $processor->process($source); } //We will need only first tag line $target = explode("\n", $token[HtmlTokenizer::TOKEN_CONTENT])[0]; //Let's try to locate place where exception was used $lines = explode("\n", $source); foreach ($lines as $number => $line) { if (strpos($line, $target) !== false) { //We found where token were used (!!) $exception->setLocation($this->compiler->getFilename(), $number + 1); return $exception; } } return $exception; }
/** * Get evaluation unique id, requried to prevent collisions. * * @return string */ protected function uniqueID() { return spl_object_hash($this) . '-' . md5($this->compiler->compiledFilename()); }