vendor/jackalope/jackalope/src/Jackalope/Workspace.php line 191

Open in your IDE?
  1. <?php
  2. namespace Jackalope;
  3. use Jackalope\Lock\LockManager;
  4. use Jackalope\Observation\ObservationManager;
  5. use Jackalope\Query\QueryManager;
  6. use Jackalope\Version\VersionManager;
  7. use PHPCR\Lock\LockManagerInterface;
  8. use PHPCR\Observation\ObservationManagerInterface;
  9. use PHPCR\WorkspaceInterface;
  10. use PHPCR\UnsupportedRepositoryOperationException;
  11. use PHPCR\Transaction\UserTransactionInterface;
  12. use Jackalope\NodeType\NodeTypeManager;
  13. use Jackalope\ImportExport\ImportExport;
  14. use Jackalope\Transport\QueryInterface;
  15. use Jackalope\Transport\WritingInterface;
  16. use Jackalope\Transport\WorkspaceManagementInterface;
  17. use Jackalope\Transport\VersioningInterface;
  18. use Jackalope\Transport\TransactionInterface;
  19. use Jackalope\Transport\LockingInterface;
  20. use Jackalope\Transport\ObservationInterface;
  21. /**
  22.  * {@inheritDoc}
  23.  *
  24.  * @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
  25.  * @license http://opensource.org/licenses/MIT MIT License
  26.  *
  27.  * @api
  28.  */
  29. class Workspace implements WorkspaceInterface
  30. {
  31.     /**
  32.      * The factory to instantiate objects
  33.      *
  34.      * @var FactoryInterface
  35.      */
  36.     protected $factory;
  37.     /**
  38.      * @var Session
  39.      */
  40.     protected $session;
  41.     /**
  42.      * @var NodeTypeManager
  43.      */
  44.     protected $nodeTypeManager;
  45.     /**
  46.      * @var UserTransactionInterface
  47.      */
  48.     protected $userTransactionManager null;
  49.     /**
  50.      * The name of the workspace this workspace represents
  51.      *
  52.      * @var string
  53.      */
  54.     protected $name;
  55.     /**
  56.      * The namespace registry.
  57.      *
  58.      * @var NamespaceRegistry
  59.      */
  60.     protected $namespaceRegistry;
  61.     /**
  62.      * @var LockManagerInterface
  63.      */
  64.     protected $lockManager;
  65.     /**
  66.      * @var ObservationManagerInterface
  67.      */
  68.     protected $observationManager;
  69.     /**
  70.      * Instantiate a workspace referencing a workspace in the storage.
  71.      *
  72.      * @param FactoryInterface $factory       the object factory
  73.      * @param Session          $session
  74.      * @param ObjectManager    $objectManager
  75.      * @param string           $name          the workspace name that is used
  76.      */
  77.     public function __construct(FactoryInterface $factorySession $sessionObjectManager $objectManager$name)
  78.     {
  79.         $this->factory $factory;
  80.         $this->session $session;
  81.         $this->nodeTypeManager $this->factory->get(NodeTypeManager::class, [$objectManager$this->getNamespaceRegistry()]);
  82.         $this->name $name;
  83.     }
  84.     /**
  85.      * {@inheritDoc}
  86.      *
  87.      * @api
  88.      */
  89.     public function getSession()
  90.     {
  91.         return $this->session;
  92.     }
  93.     /**
  94.      * {@inheritDoc}
  95.      *
  96.      * @api
  97.      */
  98.     public function getName()
  99.     {
  100.         return $this->name;
  101.     }
  102.     /**
  103.      * {@inheritDoc}
  104.      *
  105.      * @api
  106.      */
  107.     public function copy($srcAbsPath$destAbsPath$srcWorkspace null)
  108.     {
  109.         $this->session->getObjectManager()->copyNodeImmediately($srcAbsPath$destAbsPath$srcWorkspace);
  110.     }
  111.     /**
  112.      * {@inheritDoc}
  113.      *
  114.      * @api
  115.      */
  116.     public function cloneFrom($srcWorkspace$srcAbsPath$destAbsPath$removeExisting)
  117.     {
  118.         if (! $this->session->getObjectManager()->getTransport() instanceof WritingInterface) {
  119.             throw new UnsupportedRepositoryOperationException('Transport does not support writing');
  120.         }
  121.         $this->session
  122.             ->getObjectManager()
  123.             ->cloneFromImmediately($srcWorkspace$srcAbsPath$destAbsPath$removeExisting);
  124.     }
  125.     /**
  126.      * {@inheritDoc}
  127.      *
  128.      * @api
  129.      */
  130.     public function move($srcAbsPath$destAbsPath)
  131.     {
  132.         $this->session->getObjectManager()->moveNodeImmediately($srcAbsPath$destAbsPath);
  133.     }
  134.     /**
  135.      * {@inheritDoc}
  136.      *
  137.      * @api
  138.      */
  139.     public function removeItem($absPath)
  140.     {
  141.         $this->session->getObjectManager()->removeItemImmediately($absPath);
  142.     }
  143.     /**
  144.      * {@inheritDoc}
  145.      *
  146.      * @api
  147.      */
  148.     public function getLockManager()
  149.     {
  150.         if (! $this->session->getTransport() instanceof LockingInterface) {
  151.             throw new UnsupportedRepositoryOperationException('Transport does not support locking');
  152.         }
  153.         if (null === $this->lockManager) {
  154.             $this->lockManager $this->factory->get(
  155.                 LockManager::class,
  156.                 [
  157.                     $this->session->getObjectManager(),
  158.                     $this->session,
  159.                     $this->session->getTransport()
  160.                 ]
  161.             );
  162.         }
  163.         return $this->lockManager;
  164.     }
  165.     /**
  166.      * {@inheritDoc}
  167.      *
  168.      * @api
  169.      */
  170.     public function getQueryManager()
  171.     {
  172.         if (! $this->session->getTransport() instanceof QueryInterface) {
  173.             throw new UnsupportedRepositoryOperationException('Transport does not support queries');
  174.         }
  175.         return $this->factory->get(QueryManager::class, [$this->session->getObjectManager()]);
  176.     }
  177.     /**
  178.      * Sets the TransactionManager
  179.      *
  180.      * Called by the repository if transactions are enabled. Transactions are
  181.      * enabled if this is called with a non-null argument, disabled otherwise.
  182.      *
  183.      * @param UserTransactionInterface $userTransactionManager A UserTransaction object
  184.      *
  185.      * @private
  186.      */
  187.     public function setTransactionManager(UserTransactionInterface $userTransactionManager)
  188.     {
  189.         if (! $this->session->getTransport() instanceof TransactionInterface) {
  190.             throw new UnsupportedRepositoryOperationException('Transport does not support transactions');
  191.         }
  192.         $this->userTransactionManager $userTransactionManager;
  193.     }
  194.     /**
  195.      * {@inheritDoc}
  196.      *
  197.      * @api
  198.      */
  199.     public function getTransactionManager()
  200.     {
  201.         if (! $this->session->getTransport() instanceof TransactionInterface) {
  202.             throw new UnsupportedRepositoryOperationException('Transport does not support transactions');
  203.         }
  204.         if (! $this->userTransactionManager) {
  205.             throw new UnsupportedRepositoryOperationException('Transactions are currently disabled');
  206.         }
  207.         return $this->userTransactionManager;
  208.     }
  209.     /**
  210.      * {@inheritDoc}
  211.      *
  212.      * @api
  213.      */
  214.     public function getNamespaceRegistry()
  215.     {
  216.         if ($this->namespaceRegistry === null) {
  217.             $this->namespaceRegistry $this->factory->get(NamespaceRegistry::class, [$this->session->getTransport()]);
  218.         }
  219.         return $this->namespaceRegistry;
  220.     }
  221.     /**
  222.      * {@inheritDoc}
  223.      *
  224.      * @api
  225.      */
  226.     public function getNodeTypeManager()
  227.     {
  228.         return $this->nodeTypeManager;
  229.     }
  230.     /**
  231.      * {@inheritDoc}
  232.      *
  233.      * @api
  234.      */
  235.     public function getObservationManager()
  236.     {
  237.         if (! $this->session->getTransport() instanceof ObservationInterface) {
  238.             throw new UnsupportedRepositoryOperationException('Transport does not support observation');
  239.         }
  240.         if (is_null($this->observationManager)) {
  241.             $this->observationManager $this->factory->get(
  242.                 ObservationManager::class,
  243.                 [
  244.                     $this->session,
  245.                     $this->session->getTransport()
  246.                 ]
  247.             );
  248.         }
  249.         return $this->observationManager;
  250.     }
  251.     /**
  252.      * {@inheritDoc}
  253.      *
  254.      * @api
  255.      */
  256.     public function getRepositoryManager()
  257.     {
  258.         throw new UnsupportedRepositoryOperationException();
  259.     }
  260.     /**
  261.      * {@inheritDoc}
  262.      *
  263.      * @api
  264.      */
  265.     public function getVersionManager()
  266.     {
  267.         if (! $this->session->getTransport() instanceof VersioningInterface) {
  268.             throw new UnsupportedRepositoryOperationException('Transport does not support versioning');
  269.         }
  270.         return $this->factory->get(VersionManager::class, [$this->session->getObjectManager()]);
  271.     }
  272.     /**
  273.      * {@inheritDoc}
  274.      *
  275.      * @api
  276.      */
  277.     public function getAccessibleWorkspaceNames()
  278.     {
  279.         return $this->session->getTransport()->getAccessibleWorkspaceNames();
  280.     }
  281.     /**
  282.      * {@inheritDoc}
  283.      *
  284.      * @api
  285.      */
  286.     public function importXML($parentAbsPath$uri$uuidBehavior)
  287.     {
  288.         ImportExport::importXML(
  289.             $this->getSession()->getNode($parentAbsPath),
  290.             $this->getNamespaceRegistry(),
  291.             $uri,
  292.             $uuidBehavior
  293.         );
  294.     }
  295.     /**
  296.      * {@inheritDoc}
  297.      *
  298.      * @api
  299.      */
  300.     public function createWorkspace($name$srcWorkspace null)
  301.     {
  302.         if (! $this->session->getTransport() instanceof WorkspaceManagementInterface) {
  303.             throw new UnsupportedRepositoryOperationException('Transport does not support workspace management');
  304.         }
  305.         return $this->session->getTransport()->createWorkspace($name$srcWorkspace);
  306.     }
  307.     /**
  308.      * {@inheritDoc}
  309.      *
  310.      * @api
  311.      */
  312.     public function deleteWorkspace($name)
  313.     {
  314.         if (! $this->session->getTransport() instanceof WorkspaceManagementInterface) {
  315.             throw new UnsupportedRepositoryOperationException('Transport does not support workspace management');
  316.         }
  317.         return $this->session->getTransport()->deleteWorkspace($name);
  318.     }
  319. }