public function respond(Response $response) { if ($this->page instanceof Identifier) { $fullClassName = $this->page->getFullyQualifiedName(); $page = new $fullClassName(); $page->internalInitialize(); } else { $page = $this->page; } if ($page == null) { $GLOBALS['requestCycle']->addTarget(new PageNotFoundRequestTarget()); return; } $listener = $this->getListener($page); if ($listener == null) { $page->beforePageRender(); $listener = $this->getListener($page); } if ($listener == null || !$listener instanceof Listener) { throw new \RuntimeException(sprintf("Listener component %s was not found", $this->componentPath)); } if ($GLOBALS['requestCycle']->getRequest()->isAjax() == false) { $url = $GLOBALS['requestCycle']->generateUrl(new PageInstanceRequestTarget($page)); PageMap::get()->addOrUpdate($page); $GLOBALS['requestCycle']->addTarget(new RedirectRequestTarget($url)); } $listener->onEvent(); }
public function afterPageRender() { parent::afterPageRender(); if (!$this->isPageStateless()) { PageMap::get()->addOrUpdate($this); } FeedbackModel::get()->cleanup(); }
/** * @param Request $request * @todo alter expression to handle page params * @todo this is duplicated from PageRequestTarget, needs refactoring * @return type */ private function getPageClassForPath(Request $request) { $mapEntry = PageMap::getPageMap(); foreach ($mapEntry as $path => $pageClass) { if (preg_match("/^" . $this->prepare($request->getRootPath()) . "\\/" . $path . "{1}([?|&]{1}\\S+={1}\\S+)*\$/", $request->getPath())) { return $pageClass::getIdentifier(); } } return false; }
public function generateUrl(RequestTarget $target) { if ($target instanceof PageInstanceRequestTarget) { $page = $target->getPage(); PageMap::get()->addOrUpdate($page); return '?pageid=' . $page->getId(); } else { throw new \InvalidArgumentException('Expecting PageInstanceRequestTarget'); } }
public function initialise() { parent::initialise(); PageMap::get()->initialise(); }
/** * Set the current page * @param mixed $page An instance of web page or an Identifier for a web page * @todo add page params */ public function setPage($page) { Args::notNull($page, 'page'); if ($page instanceof Identifier) { if ($page->of(WebPage::getIdentifier())) { $target = new PageRequestTarget($page); } else { throw new \InvalidArgumentException("Expected identifier to be for a web page"); } } else { if ($page instanceof WebPage) { PageMap::get()->addOrUpdate($page); $target = new PageInstanceRequestTarget($page); } else { throw new \InvalidArgumentException(sprintf("setPage expects an identifier for a web page or an instance of a web page and not a %s", get_class($page))); } } if ($this->getRequestCycle()->containsTarget(ListenerRequestTarget::getIdentifier())) { $url = $this->getRequestCycle()->generateUrl($target); $this->getRequestCycle()->addTarget(new RedirectRequestTarget($url)); } else { $this->getRequestCycle()->addTarget($target); } }