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

  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\PathNotFoundException;
  12. use PHPCR\SessionInterface;
  13. class SessionManager implements SessionManagerInterface
  14. {
  15.     /**
  16.      * @var string[]
  17.      */
  18.     private $nodeNames;
  19.     /**
  20.      * @var SessionInterface
  21.      */
  22.     private $session;
  23.     public function __construct(SessionInterface $session$nodeNames)
  24.     {
  25.         $this->session $session;
  26.         $this->nodeNames $nodeNames;
  27.     }
  28.     public function getSession()
  29.     {
  30.         return $this->session;
  31.     }
  32.     public function getRouteNode($webspaceKey$languageCode$segment null)
  33.     {
  34.         return $this->getSession()->getNode($this->getRoutePath($webspaceKey$languageCode$segment));
  35.     }
  36.     public function getRoutePath($webspaceKey$languageCode$segment null)
  37.     {
  38.         $path \sprintf(
  39.             '/%s/%s/%s/%s%s',
  40.             $this->nodeNames['base'],
  41.             $webspaceKey,
  42.             $this->nodeNames['route'],
  43.             $languageCode,
  44.             null !== $segment '/' $segment ''
  45.         );
  46.         return $path;
  47.     }
  48.     public function getContentNode($webspaceKey)
  49.     {
  50.         return $this->getSession()->getNode($this->getContentPath($webspaceKey));
  51.     }
  52.     public function getContentPath($webspaceKey)
  53.     {
  54.         $path \sprintf(
  55.             '/%s/%s/%s',
  56.             $this->nodeNames['base'],
  57.             $webspaceKey,
  58.             $this->nodeNames['content']
  59.         );
  60.         return $path;
  61.     }
  62.     public function getWebspaceNode($webspaceKey)
  63.     {
  64.         return $this->getSession()->getNode($this->getWebspacePath($webspaceKey));
  65.     }
  66.     public function getWebspacePath($webspaceKey)
  67.     {
  68.         return \sprintf(
  69.             '/%s/%s',
  70.             $this->nodeNames['base'],
  71.             $webspaceKey
  72.         );
  73.     }
  74.     public function getSnippetNode($templateKey null)
  75.     {
  76.         $snippetPath '/' $this->nodeNames['base'] . '/' $this->nodeNames['snippet'];
  77.         $nodePath $snippetPath '/' $templateKey;
  78.         if (null === $templateKey) {
  79.             $nodePath $snippetPath;
  80.         }
  81.         try {
  82.             $node $this->getSession()->getNode($nodePath);
  83.         } catch (PathNotFoundException $e) {
  84.             $node $this->getSession()->getNode($snippetPath)->addNode($templateKey);
  85.         }
  86.         return $node;
  87.     }
  88. }