public function getView() { if (is_null($this->view)) { $viewConfig = $this->getConfig('view'); $viewAdapter = $this->getConfig(['view', 'adapter'], 'Twig'); /** @var InterfaceView view */ $this->view = ViewFactory::getView($viewAdapter, $viewConfig); //set templates dir if ($this->view instanceof TwigView) { $mm = $this->getModuleManager(); $modules = $mm->getModulesList(); foreach ($modules as $moduleName) { $templatesPath = $mm->getModulePath($moduleName) . "/templates"; if (file_exists($templatesPath . "/{$moduleName}")) { $this->getView()->addTemplateDir($templatesPath); } } } $viewVars = $this->getConfig(['view', 'vars']); if ($viewVars instanceof Config) { $viewVars = $viewVars->toArray(); } if (!empty($viewVars) && is_array($viewVars)) { foreach ($viewVars as $name => $value) { if (is_callable($value)) { $value = call_user_func($value, $this); } $this->view->assign($name, $value); } } } return $this->view; }
/** * @return InterfaceView */ public function getView() { if (is_null($this->view)) { $viewAdapter = $this->getConfig(['view', 'adapter'], 'twig'); $this->view = ViewFactory::getView($viewAdapter, $this->getConfig('view')); } return $this->view; }