public searchPage ( ) : |
||
Результат |
public function searchPage()
{
$url = $this->getRequest()->getPathInfo();
$page = null;
$title = sprintf('Searching Page [%s]', $url);
$this->stopwatch->start($title);
if (!$page) {
$domain = $this->pageStack->getCurrentDomain();
$urls = $this->pageStack->getCachedUrlToPage($domain->getId());
$possibleUrl = $url;
$id = false;
while (1) {
if (isset($urls[$possibleUrl])) {
$id = $urls[$possibleUrl];
break;
}
if (false !== ($pos = strrpos($possibleUrl, '/'))) {
$possibleUrl = substr($possibleUrl, 0, $pos);
} else {
break;
}
}
if (!$id) {
//set to startpage
$id = $domain->getStartnodeId();
$possibleUrl = '/';
}
$url = $possibleUrl;
if ($url == '/') {
$pageId = $this->pageStack->getCurrentDomain()->getStartnodeId();
if (!$pageId > 0) {
$this->eventDispatcher->dispatch('core/domain-no-start-page');
}
} else {
$pageId = $id;
}
/** @var \Jarves\Model\Node $page */
$page = $this->pageStack->getPage($pageId);
}
$this->stopwatch->stop($title);
return $page;
}
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { //we need to reset all routes. They will anyway replaced by FrontendRouter::loadRoutes, //but to prevent caching conflicts, when a user removes a plugin for example //from a page, we need to know that without using actual caching. $this->routes = new RouteCollection(); $this->urlMatcher->__construct($this->routes, $this->requestContext); //prepare for new master request: clear the PageResponse object $this->pageStack->setCurrentPage(null); $this->pageStack->setCurrentDomain(null); $this->pageStack->setPageResponse($this->pageResponseFactory->create()); $this->frontendRouter->setRequest($request); $editorNodeId = (int) $this->pageStack->getRequest()->get('_jarves_editor_node'); $editorDomainId = (int) $this->pageStack->getRequest()->get('_jarves_editor_domain'); $domain = null; if ($editorDomainId) { $domain = $this->pageStack->getDomain($editorDomainId); if (!$domain) { //we haven't found any domain that is responsible for this request return; } $this->pageStack->setCurrentDomain($domain); } if ($editorNodeId) { //handle jarves content editor stuff //access is later checked if (!$editorNodeId && $domain) { $editorNodeId = $domain->getStartnodeId(); } $page = $this->pageStack->getPage($editorNodeId); if (!$page || !$page->isRenderable()) { //we haven't found any page that is responsible for this request return; } if (!$domain) { $domain = $this->pageStack->getDomain($page->getDomainId()); } $this->pageStack->setCurrentPage($page); $this->pageStack->setCurrentDomain($domain); $request->attributes->set('_controller', 'jarves.page_controller:handleAction'); } else { //regular frontend route search //search domain if (!$domain) { $domain = $this->frontendRouter->searchDomain(); if (!$domain) { //we haven't found any domain that is responsible for this request return; } $this->pageStack->setCurrentDomain($domain); } //search page $page = $this->frontendRouter->searchPage(); if (!$page || !$page->isRenderable()) { //we haven't found any page that is responsible for this request return; } $this->pageStack->setCurrentPage($page); if ($response = $this->frontendRouter->loadRoutes($this->routes, $page)) { //loadRoutes return in case of redirects and permissions a redirect or 404 response. $event->setResponse($response); return; } try { //check routes in $this->route parent::onKernelRequest($event); } catch (MethodNotAllowedException $e) { } catch (NotFoundHttpException $e) { } } } }