vendor/sulu/sulu/src/Sulu/Component/PHPCR/SessionManager/SessionManager.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\PHPCR\SessionManager;
  11. use PHPCR\SessionInterface;
  12. class SessionManager implements SessionManagerInterface
  13. {
  14.     /**
  15.      * @var string[]
  16.      */
  17.     private $nodeNames;
  18.     /**
  19.      * @var SessionInterface
  20.      */
  21.     private $session;
  22.     public function __construct(SessionInterface $session$nodeNames)
  23.     {
  24.         $this->session $session;
  25.         $this->nodeNames $nodeNames;
  26.     }
  27.     public function getSession()
  28.     {
  29.         return $this->session;
  30.     }
  31.     public function getRouteNode($webspaceKey$languageCode$segment null)
  32.     {
  33.         return $this->getSession()->getNode($this->getRoutePath($webspaceKey$languageCode$segment));
  34.     }
  35.     public function getRoutePath($webspaceKey$languageCode$segment null)
  36.     {
  37.         $path = \sprintf(
  38.             '/%s/%s/%s/%s%s',
  39.             $this->nodeNames['base'],
  40.             $webspaceKey,
  41.             $this->nodeNames['route'],
  42.             $languageCode,
  43.             null !== $segment '/' $segment ''
  44.         );
  45.         return $path;
  46.     }
  47.     public function getContentNode($webspaceKey)
  48.     {
  49.         return $this->getSession()->getNode($this->getContentPath($webspaceKey));
  50.     }
  51.     public function getContentPath($webspaceKey)
  52.     {
  53.         $path = \sprintf(
  54.             '/%s/%s/%s',
  55.             $this->nodeNames['base'],
  56.             $webspaceKey,
  57.             $this->nodeNames['content']
  58.         );
  59.         return $path;
  60.     }
  61.     public function getWebspaceNode($webspaceKey)
  62.     {
  63.         return $this->getSession()->getNode($this->getWebspacePath($webspaceKey));
  64.     }
  65.     public function getWebspacePath($webspaceKey)
  66.     {
  67.         return \sprintf(
  68.             '/%s/%s',
  69.             $this->nodeNames['base'],
  70.             $webspaceKey
  71.         );
  72.     }
  73.     public function getSnippetNode($templateKey null)
  74.     {
  75.         $snippetPath '/' $this->nodeNames['base'] . '/' $this->nodeNames['snippet'];
  76.         $nodePath $snippetPath '/' $templateKey;
  77.         if (null === $templateKey) {
  78.             $nodePath $snippetPath;
  79.         }
  80.         try {
  81.             $node $this->getSession()->getNode($nodePath);
  82.         } catch (\PHPCR\PathNotFoundException $e) {
  83.             $node $this->getSession()->getNode($snippetPath)->addNode($templateKey);
  84.         }
  85.         return $node;
  86.     }
  87. }