/** * Finishes and saves the snippet. * @return void */ public function finish() { if ($this->tag !== NULL) { // rendering flow or non-AJAX request if ($this->tag) { echo "</{$this->tag}>"; } } else { // finish snippet buffering if ($this->level !== ob_get_level()) { throw new InvalidStateException("Snippet '{$this->id}' cannot be ended here."); } $this->payload->snippets[$this->id] = ob_get_clean(); self::$outputAllowed = FALSE; } }
/** * @return void * @throws BadRequestException if no template found */ public function renderTemplate() { $template = $this->getTemplate(); if (!$template) { return; } if ($this->isAjax()) { // TODO! SnippetHelper::$outputAllowed = FALSE; } if ($template instanceof IFileTemplate && !$template->getFile()) { if (isset($template->layout)) { trigger_error('Parameter $template->layout is about to be reserved.', E_USER_WARNING); } unset($template->layout, $template->content); // content template $files = $this->formatTemplateFiles($this->getName(), $this->view); foreach ($files as $file) { if (is_file($file)) { $template->setFile($file); break; } } if (!$template->getFile()) { $file = reset($files); throw new BadRequestException("Page not found. Missing template '{$file}'."); } // layout template if ($this->layout) { foreach ($this->formatLayoutTemplateFiles($this->getName(), $this->layout) as $file) { if (is_file($file)) { if ($this->oldLayoutMode) { $template->content = $template instanceof Template ? $template->subTemplate($template->getFile()) : $template->getFile(); $template->setFile($file); } else { $template->layout = $file; // experimental } break; } } } } $template->render(); }
/** * @return void * @throws BadRequestException if no template found * @throws AbortException */ public function sendTemplate() { $template = $this->getTemplate(); if (!$template) { return; } if ($template instanceof IFileTemplate && !$template->getFile()) { // content template $files = $this->formatTemplateFiles($this->getName(), $this->view); foreach ($files as $file) { if (is_file($file)) { $template->setFile($file); break; } } if (!$template->getFile()) { $file = str_replace(Environment::getVariable('templatesDir'), "…", reset($files)); throw new BadRequestException("Page not found. Missing template '{$file}'."); } // layout template if ($this->layout) { foreach ($this->formatLayoutTemplateFiles($this->getName(), $this->layout) as $file) { if (is_file($file)) { if ($this->oldLayoutMode) { $template->content = clone $template; $template->setFile($file); } else { $template->layout = $template->_extends = $file; } break; } } } } if ($this->isAjax()) { // TODO! /*Nette\Templates\*/ SnippetHelper::$outputAllowed = FALSE; $template->render(); $this->sendPayload(); } $this->terminate(new RenderResponse($template)); }
/** * @param PresenterRequest * @return IPresenterResponse */ public function run(PresenterRequest $request) { try { // STARTUP $this->request = $request; $this->payload = (object) NULL; $this->setParent($this->getParent(), $request->getPresenterName()); $this->initGlobalParams(); $this->startup(); if (!$this->startupCheck) { $class = $this->reflection->getMethod('startup')->getDeclaringClass()->getName(); trigger_error("Method {$class}::startup() or its descendant doesn't call parent::startup().", E_USER_WARNING); } // calls $this->action<Action>() $this->tryCall($this->formatActionMethod($this->getAction()), $this->params); if ($this->autoCanonicalize) { $this->canonicalize(); } if ($this->getHttpRequest()->isMethod('head')) { $this->terminate(); } // SIGNAL HANDLING // calls $this->handle<Signal>() $this->processSignal(); // RENDERING VIEW $this->beforeRender(); // calls $this->render<View>() $this->tryCall($this->formatRenderMethod($this->getView()), $this->params); $this->afterRender(); // save component tree persistent state $this->saveGlobalState(); if ($this->isAjax()) { $this->payload->state = $this->getGlobalState(); } // finish template rendering $this->sendTemplate(); } catch (AbortException $e) { // continue with shutting down } if ($this->isAjax()) { try { $hasPayload = (array) $this->payload; unset($hasPayload['state']); if ($this->response instanceof RenderResponse && ($this->isControlInvalid() || $hasPayload)) { // snippets - TODO SnippetHelper::$outputAllowed = FALSE; $this->response->send(); $this->sendPayload(); } elseif (!$this->response && $hasPayload) { // back compatibility for use terminate() instead of sendPayload() $this->sendPayload(); } } catch (AbortException $e) { } } if ($this->hasFlashSession()) { $this->getFlashSession()->setExpiration($this->response instanceof RedirectingResponse ? '+ 30 seconds' : '+ 3 seconds'); } // SHUTDOWN $this->onShutdown($this, $this->response); $this->shutdown($this->response); return $this->response; }
function finish() { if ($this->tag !== NULL) { if ($this->tag) { echo "</{$this->tag}>"; } } else { if ($this->level !== ob_get_level()) { throw new InvalidStateException("Snippet '{$this->id}' cannot be ended here."); } $this->payload->snippets[$this->id] = ob_get_clean(); self::$outputAllowed = FALSE; } }