Example #1
0
 /**
  * Returns a distributed cache value.
  *
  * This uses cache invalidation mechanism described in
  *
  * @see setDistributedCache() for more information invalidateCache().
  *
  * @param string $key
  *
  * @return mixed null when not found
  */
 public function getDistributedCache($key)
 {
     $this->stopwatch->start(sprintf('Get Cache `%s`', $key));
     $cache = $this->fastCache->get($key);
     if (null === $cache) {
         $this->stopwatch->stop(sprintf('Get Cache `%s`', $key));
         return null;
     }
     if (!is_array($cache) || !isset($cache['timestamp'])) {
         throw new \RuntimeException(sprintf('You requested a cache through the distributed cache mechanism, which was not ' . 'set through this mechanism. You can only distributed cache when you set the cache through the' . 'distributed cache. [%s]', substr($cache, 0, 50)));
     }
     $isValid = $this->isCacheIsValid($key, $cache['timestamp']);
     $this->stopwatch->stop(sprintf('Get Cache `%s`', $key));
     return $isValid ? $cache['data'] : null;
 }
Example #2
0
 /**
  * Build HTML for given content.
  *
  * @param ContentInterface $content
  * @param array $parameters
  * @return string
  * @throws TypeNotFoundException
  */
 public function renderContent(ContentInterface $content, $parameters = array())
 {
     $type = $content->getType() ?: 'text';
     if ('stopper' === $type) {
         return '';
     }
     $title = sprintf('Content %d [%s]', $content->getId(), $type);
     $this->stopwatch->start($title, 'Jarves');
     $typeRenderer = $this->getTypeRenderer($type);
     if (!$typeRenderer) {
         $this->stopwatch->stop($title);
         throw new TypeNotFoundException(sprintf('Type renderer for `%s` not found. [%s] %s', $type, json_encode($content), json_encode(array_keys($this->types))));
     }
     $typeRenderer->setContent($content);
     $typeRenderer->setParameters($parameters);
     $html = $typeRenderer->render();
     $data['content'] = $content->toArray(TableMap::TYPE_CAMELNAME);
     $data['parameter'] = $parameters;
     $data['html'] = $html;
     $this->eventDispatcher->dispatch('core/render/content/pre', new GenericEvent($data));
     $unsearchable = false;
     if (!is_array($content->getAccessFromGroups()) && $content->getAccessFromGroups() != '' || is_array($content->getAccessFromGroups()) && count($content->getAccessFromGroups()) > 0 || $content->getAccessFrom() > 0 && $content->getAccessFrom() > time() || $content->getAccessTo() > 0 && $content->getAccessTo() < time() || $content->getUnsearchable()) {
         $unsearchable = true;
     }
     if ($html) {
         if ($content->getTemplate() == '' || $content->getTemplate() == '-') {
             if ($unsearchable && $data['html']) {
                 $result = '<!--unsearchable-begin-->' . $data['html'] . '<!--unsearchable-end-->';
             } else {
                 $result = $data['html'];
             }
         } else {
             $result = $this->templating->render($content->getTemplate(), $data);
             if ($unsearchable && $result) {
                 $result = '<!--unsearchable-begin-->' . $result . '<!--unsearchable-end-->';
             }
         }
     }
     $argument = array(&$result, $data);
     $this->eventDispatcher->dispatch('core/render/content', new GenericEvent($argument));
     $this->stopwatch->stop($title);
     return $result;
 }
Example #3
0
 /**
  * Returns the id of given path-info. Null if not existent.
  *
  * @return Node|null
  */
 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;
 }
Example #4
0
 /**
  * Builds the html body of the current page.
  *
  * @return string
  * @throws \Exception
  */
 public function buildBody()
 {
     $this->stopwatch->start('Build PageBody');
     if (!($page = $this->pageStack->getCurrentPage())) {
         $this->stopwatch->stop('Build PageBody');
         return '';
     }
     $themeId = $page->getTheme();
     if (!$themeId && $this->pageStack->getCurrentDomain()) {
         $themeId = $this->pageStack->getCurrentDomain()->getTheme();
     }
     if (!$themeId) {
         throw new \LogicException('PageResponse class was not able to find a theme to use for rendering the body. Define one at the currentPage or currentDomain of PageStack.');
     }
     if (!($theme = $this->jarves->getConfigs()->getTheme($themeId))) {
         $this->stopwatch->stop('Build PageBody');
         throw new \LogicException(sprintf('Theme `%s` not found.', $themeId));
     }
     $layoutKey = $this->getLayout($page);
     $layout = $theme->getLayoutByKey($layoutKey);
     if ('_tray' === $layoutKey && !$layout) {
         $layout = new ThemeLayout();
         $layout->setFile('JarvesBundle:Default:tray.html.twig');
     }
     if (!$layout) {
         $this->stopwatch->stop('Build PageBody');
         throw new \LogicException(sprintf('Layout for `%s` in theme `%s` not found.', $layoutKey, $themeId));
     }
     $layoutPath = $layout->getFile();
     try {
         $html = $this->templating->render($layoutPath, $this->getPageViewParameter());
     } catch (\Exception $e) {
         throw new \Exception(sprintf('Cant render view `%s` of theme `%s`.', $layoutPath, $themeId), 0, $e);
     }
     $this->stopwatch->stop('Build PageBody');
     return $html;
 }