/** * @inheritdoc */ public function compile(IView $view) { // Set some variables that will be used by the transpiled code $view->setContents($this->transpiler->transpile($view)); $view->setVars(["__opulenceView" => $view, "__opulenceFortuneTranspiler" => $this->transpiler, "__opulenceViewFactory" => $this->viewFactory]); return trim(parent::compile($view)); }
/** * @inheritdoc */ public function addParent(IView $parent, IView $child) { foreach ($parent->getVars() as $name => $value) { if (!$child->hasVar($name)) { $child->setVar($name, $value); } } }
/** * Gets the extension for a view * * @param IView $view The view whose extension we're getting * @return string The view's extension * @throws InvalidArgumentException Thrown if no extension was found */ protected function getExtension(IView $view) { // Find a registered extension that the view's path ends with foreach (array_keys($this->compilers) as $extension) { $lengthDifference = strlen($view->getPath()) - strlen($extension); if ($lengthDifference >= 0 && strpos($view->getPath(), $extension, $lengthDifference) !== false) { return $extension; } } throw new InvalidArgumentException("No extension registered for path \"{$view->getPath()}\""); }
/** * @inheritdoc */ public function compile(IView $view) { $obStartLevel = ob_get_level(); ob_start(); extract($view->getVars()); try { if (eval('?>' . $view->getContents()) === false) { throw new ViewCompilerException("Invalid PHP in view"); } } catch (Exception $ex) { $this->handleException($ex, $obStartLevel); } catch (Throwable $ex) { $this->handleException($ex, $obStartLevel); } return ob_get_clean(); }