/** * This method is intend to render the current state of the view as html. For this it makes use of the base * template engine, and html5 template files. If you need another output or something like this, you must * overwrite this method. * * @param array $data The data as override for internal stored data * @param string $fingerprint Optional fingerprint used as cache identifier for front- and * backend! Hint: Rendering user specific data an user identifier * MUST be used as salt when generating the fingerprint!!! * Otherwise user specific data can and will be sent to another * user!. So the following rule should be followed: * - generic view/template no user data = fingerprint by * content/path/url * - user specific view/template with user data = use * session-id or user-id! * @param Doozr_I18n_Service_Interface $i18n An instance of a Doozr I18n service * * @author Benjamin Carl <*****@*****.**> * * @return bool TRUE if successful, otherwise FALSE * * @throws Doozr_Cache_Service_Exception * @throws Doozr_Base_View_Exception * @throws Doozr_Exception * @throws PHPTAL_ConfigurationException */ protected function render(array $data = [], $fingerprint = null, Doozr_I18n_Service_Interface $i18n = null) { $this->setFingerprint($this->generateFingerprint($fingerprint, $data)); $html = null; if (false === $this->getConfiguration()->kernel->debugging->enabled) { // We try to receive data for rendering from cache :) this is much faster try { $html = $this->cache->read($this->getFingerprint()); } catch (Doozr_Cache_Service_Exception $e) { $html = null; } } // If data was/could not be retrieved we get it fresh here ... if ($html === null) { // Get name of template file $templateFile = $this->configuration->kernel->view->template->path . $this->translateToTemplateFilename() . '.' . $this->getTemplateExtension(); if (false === $this->getRegistry()->getFilesystem()->exists($templateFile)) { throw new Doozr_Base_View_Exception(sprintf('The template file "%s" is required for rendering but it does not exist.', $templateFile)); } /* @var $template PHPTAL */ $template = Doozr_Loader_Serviceloader::load('template', $templateFile); // Set output runtimeEnvironment ... $template->setOutputMode($this->getOutputMode()); // if I18n passed -> forward to template engine (e.g. PHPTAL) if (null !== $i18n) { $i18n->useDomain($this->translateToTextdomain()); $template->setTranslator($i18n); $template->{'doozr_locale'} = $i18n->getLocale(); } // Assign data from passed in array to template (for use as a template variable) foreach ($data as $key => $value) { $template->{$key} = $value; } // setup template compile output dir $template->setPhpCodeDestination($this->configuration->kernel->view->directories->compiled); // set the encoding of output $template->setEncoding($this->configuration->kernel->localization->encoding); // Output XHTML or HTML5 ... ? $template->setOutputMode($this->configuration->kernel->view->settings->outputmode); // execute = get result $html = $template->execute(); if (true === $this->isDebugging()) { $renderer = $this->getRegistry()->getDebugbar()->getJavascriptRenderer(); $renderer->setBaseUrl('/assets'); $head = $renderer->renderHead(); $body = $renderer->render(); $html = str_replace('</head>', $head . '</head>', $html); $html = str_replace('</body>', $body . '</body>', $html); } // finally store in cache try { $this->cache->create($html, $this->getFingerprint()); } catch (Doozr_Cache_Service_Exception $e) { pred($e); } } return $html; }
/** * This method is intend to render the current state of the view as html. For this it makes use of the base * template engine, and html5 template files. If you need another output or something like this, you must * overwrite this method. * * @param array $data The data as override for internal stored data * @param string $fingerprint Optional fingerprint used as cache identifier for front- and * backend! Hint: Rendering user specific data an user identifier * MUST be used as salt when generating the fingerprint!!! * Otherwise user specific data can and will be sent to another * user!. So the following rule should be followed: * - generic view/template no user data = fingerprint by * content/path/url * - user specific view/template with user data = use * session-id or user-id! * @param Doozr_I18n_Service_Interface $i18n An instance of a Doozr I18n service * * @author Benjamin Carl <*****@*****.**> * * @return bool TRUE if successful, otherwise FALSE * * @throws \Doozr_Base_View_Exception */ protected function render(array $data = [], $fingerprint = null, Doozr_I18n_Service_Interface $i18n = null) { $this->setFingerprint($this->generateFingerprint($fingerprint, $data)); $html = null; // We try to receive data for rendering from cache :) this is much faster if (true === $this->getCaching()) { try { $html = $this->cache->read($this->getFingerprint()); } catch (Doozr_Cache_Service_Exception $exception) { $html = null; } } // If data was/could not be retrieved we get it fresh here ... if (null === $html) { // Get name of template file $templateFile = $this->configuration->kernel->view->template->path . $this->translateToTemplateFilename() . '.' . $this->getTemplateExtension(); if (false === $this->getRegistry()->getFilesystem()->exists($templateFile)) { throw new Doozr_Base_View_Exception(sprintf('The template file "%s" is required for rendering but it does not exist.', $templateFile)); } /* @var $template PHPTAL */ $template = Doozr_Loader_Serviceloader::load('template', $templateFile); $template->setForceReparse(true); $template->setCacheLifetime(-1); // Set output runtimeEnvironment ... $template->setOutputMode($this->getOutputMode()); // If I18n passed -> forward to template engine (e.g. PHPTAL) if (null !== $i18n) { // Try to load specific namespace/textdomain for PRESENTER+ACTION try { $i18n->useDomain($this->translateToTextdomain()); } catch (Doozr_I18n_Service_Exception $e) { // We don't care but we log for developing purposes $this->getRegistry()->getLogging()->debug($e->getMessage()); // Try to load specific namespace/textdomain for PRESENTER try { $i18n->useDomain($this->translateToTextdomain(true)); } catch (Doozr_I18n_Service_Exception $e) { // We don't care but we log for developing purposes $this->getRegistry()->getLogging()->debug($e->getMessage()); // Try to load default namespace/textdomain try { $i18n->useDomain($this->getConfiguration()->i18n->default->namespace); } catch (Doozr_I18n_Service_Exception $e) { // We don't care but we log for developing purposes $this->getRegistry()->getLogging()->debug($e->getMessage()); } } } $template->setTranslator($i18n); $template->{'doozr_locale'} = $i18n->getLocale(); } // Assign data from passed in array to template (for use as a template variable) foreach ($data as $key => $value) { $template->{$key} = $value; } // setup template compile output dir $template->setPhpCodeDestination($this->configuration->kernel->view->directories->compiled); // set the encoding of output $template->setEncoding($this->configuration->kernel->localization->encoding); // Output XHTML or HTML5 ... ? $template->setOutputMode($this->configuration->kernel->view->settings->outputmode); $html = $template->execute(); // Inject Debugbar? if (true === $this->isDebugging()) { $html = $this->injectDebugbar($html); } // Cache result? if (true === $this->getCaching()) { $this->cache->create($html, $this->getFingerprint()); } } return $html; }