Source for file Workspace.php

Documentation is available at Workspace.php

  1. <?php
  2. /**
  3.  * 
  4.  * The Workspace object represents a "view" of an actual repository workspace entity as seen through the authorization settings of its associated Session.
  5.  * Each Workspace object is associated one-to-one with a Session object.
  6.  * The Workspace object can be acquired by calling Session->getWorkspace() on the associated Session object.
  7.  * @author
  8.  * @version 1.0
  9.  * 
  10.  */
  11. class Workspace {
  12.     private $pm;
  13.     private $workspace;
  14.     
  15.     /**
  16.      * 
  17.      * Creates a new Workspace object, given an active session (i.e. PersistenceManager).
  18.      * @param generic $pm the active PersistenceManager.
  19.      * 
  20.      */
  21.     public function __construct(&$pm{
  22.         $this->pm =$pm;
  23.  
  24.         $this->workspace $pm->getWorkspace();
  25.     }
  26.  
  27.     /**
  28.      * Clones the subtree at the node $sourcePath in $workspace to the new location at $destinationPath in this workspace.
  29.      * If successful, the change is persisted immediately.
  30.      * Strictly speaking, the $destinationPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the cloned node.
  31.      * This method cannot be used to clone just an individual property by itself. It clones an entire node and its subtree (including, of course, any properties contained therein).
  32.      * A NoSuchWorkspaceException is thrown if $workspace does not exist or if the current Session does not have permission to access it.
  33.      * A PathNotFoundException is thrown if the node at $sourcePath in $workspace or the parent of $destinationPath in this workspace does not exist.
  34.      * An ItemExistsException is thrown if a node or property already exists at $destinationPath.
  35.      * An ItemExistException is thrown if a node already exists at $destinationPath.
  36.      *
  37.      * @param string $workspace - The name of the workspace from which the node is to be copied.
  38.      * @param string $sourcePath - the path of the node to be cloned in $workspace.
  39.      * @param string $destinationPath - the location to which the node at $workspace=>$sourcePath is to be cloned in this workspace.
  40.      */
  41.     public function _clone($workspace$sourcePath$destinationPath{
  42.         if (!file_exists($_SERVER['PCR'"/config/$workspace.xml")) {
  43.             throw new NoSuchWorkspaceException($workspace);
  44.         }
  45.  
  46.         $config simplexml_load_file($_SERVER['PCR'"/config/$workspace.xml");
  47.         $persistenceManager = (string) $config->persistenceManager;
  48.         
  49.         if (!file_exists($_SERVER['PCR'"/PMs/$persistenceManager.php")) {
  50.             throw new RepositoryException("persistence manager does not exist for workspace: $workspace=>$persistenceManager");
  51.         }
  52.  
  53.         require_once $_SERVER['PCR'"/PMs/$persistenceManager.php";
  54.         
  55.         $pm new $persistenceManager($this->pm->getCredentials()$workspace$config);
  56.         
  57.         if (!$pm->isLive()) {
  58.             throw new LoginException("workspace=>$workspace, persistenceManager=>$persistenceManager, userID=>$credentials->getUserID());
  59.         }
  60.         
  61.         if ($sourcePath == 'pcr:root'{
  62.             throw new RepositoryException("cannot clone reserved node: $this->workspace=>pcr:root");
  63.         else if ($pm->getNode($sourcePath=== null{
  64.             throw new PathNotFoundException("$workspace=>$sourcePath");
  65.         else if ($this->pm->getNode($destinationPath!== null{
  66.             throw new ItemExistsException("$this->workspace=>$destinationPath");
  67.         }
  68.         
  69.         $parent substr($destinationPath0strrpos($destinationPath'/'));
  70.         
  71.         if ($parent != 'pcr:root'{
  72.             if ($this->pm->getNode($parent=== null{
  73.                 throw new PathNotFoundException("$this->workspace=>$parent");
  74.             }
  75.         }
  76.  
  77.         Log4PCR::info("Cloned node (and its descendants, if any): $workspace=>$sourcePath to $this->workspace=>$destinationPath");
  78.         
  79.         $this->pm->_clone($workspace$sourcePath$destinationPath);
  80.     }
  81.     
  82.     /**
  83.      * 
  84.      * This method copies the node at $sourcePath to the new location at $destinationPath.
  85.      * If successful, the change is persisted immediately.
  86.      * Strictly speaking, the $destinationPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the copied node.
  87.      * This method cannot be used to copy just an individual property by itself.
  88.      * It copies an entire node and its subtree (including, of course, any properties contained therein).
  89.      * A PathNotFoundException is thrown if the node at $sourcePath or the parent of $destinationPath does not exist.
  90.      * An ItemExistException is thrown if a Node already exists at $destinationPath.
  91.      * @param string $sourcePath the root of the subtree to be copied.
  92.      * @param string $destinationPath the location to which the subtree is to be copied.
  93.      * 
  94.      */
  95.     public function copy($sourcePath$destinationPath{
  96.         if ($sourcePath == 'pcr:root'{
  97.             throw new RepositoryException("cannot copy reserved node: $this->workspace=>pcr:root");
  98.         else if ($this->pm->getNode($sourcePath=== null{
  99.             throw new PathNotFoundException("$this->workspace=>$sourcePath");
  100.         else if ($this->pm->getNode($destinationPath!== null{
  101.             throw new ItemExistsException("$this->workspace=>$destinationPath");
  102.         }
  103.         
  104.         $parent substr($destinationPath0strrpos($destinationPath'/'));
  105.         
  106.         if ($parent != 'pcr:root'{
  107.             if ($this->pm->getNode($parent=== null{
  108.                 throw new PathNotFoundException("$this->workspace=>$parent");
  109.             }
  110.         }
  111.                     
  112.         Log4PCR::info("Copied node (and its descendants, if any): $this->workspace=>$sourcePath to $this->workspace=>$destinationPath");
  113.         
  114.         $this->pm->copy($sourcePath$destinationPath);
  115.     }
  116.     
  117.     /**
  118.      * 
  119.      * Returns an string array containing the names of all workspaces in the repository.
  120.      * In order to access one of the listed workspaces, the user performs another Repository->login, specifying the name of the desired workspace, and receives a new Session object.
  121.      * @return array string array of names of accessible workspaces.
  122.      * 
  123.      */
  124.     public function getAccessibleWorkspaceNames({
  125.         $accessibleWorkspaceNames array();
  126.         
  127.         if ($handle opendir($_SERVER['PCR''/config')) {
  128.             while (false !== ($workspace readdir($handle))) {
  129.                 if ($workspace != '.' && $workspace != '..'{
  130.                     $accessibleWorkspaceNames[substr($workspace0strrpos($workspace'.'));
  131.                 }
  132.             }
  133.                         
  134.             closedir($handle);
  135.         }
  136.         
  137.         return $accessibleWorkspaceNames;
  138.     }
  139.     
  140.     /**
  141.      * 
  142.      * Returns the name of the actual persistent workspace represented by this Workspace object.
  143.      * @return string the name of this workspace.
  144.      * 
  145.      */
  146.     public function getName({
  147.         return $this->workspace;
  148.     }
  149.  
  150.     /**
  151.      * 
  152.      * Gets the QueryManager.
  153.      * Returns the QueryManager object, through search methods are accessed.
  154.      * @return QueryManager the QueryManager object.
  155.      * 
  156.      */
  157.     public function getQueryManager({
  158.         return new QueryManager($this->pm);
  159.     }
  160. }
  161.  
  162. ?>

Documentation generated on Sun, 04 Oct 2009 07:13:13 +0800 by phpDocumentor 1.4.3