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

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