Ejemplo n.º 1
0
 /**
  * Set the path to this file/folder. I am assuming that this does not include the 
  * name of the file/folder but am unsure. This means that if you want to rename a file
  * or folder you need to use the setName() method.
  * Setting the path should result in parent folders being created where necessary. (mkdir -p)
  * Changing the path of a folder act like updating a pointer rather than 
  * resulting in having to send queries to update all of the sub-items.
  * 
  * @param string $path - and absolute path such as /path/to/folder/or/file.php
  *
  * @return $this
  */
 public function setPath($path)
 {
     if ($path !== "" && $path !== "/") {
         $folderNames = explode("/", $path);
         array_shift($folderNames);
         $parentFolder = MongoFileSystem::loadRoot();
         foreach ($folderNames as $folderName) {
             $subFolders = $parentFolder->getSubFolders();
             $indexedSubFolders = array();
             foreach ($subFolders as $index => $subFolder) {
                 $indexedSubFolders[$subFolder->getName()] = $subFolder;
             }
             if (isset($indexedSubFolders[$subFolder])) {
                 $parentFolder = $indexedSubFolders[$subFolder];
             } else {
                 # Need to create the subfolders from here.
                 $newFolder = new MongoFolder($folderName);
                 $parentFolder = MongoFileSystem::getInstance()->createFolder($newFolder, $parentFolder);
             }
         }
         # The last "parent folder" from the loop should be the last in the path which we want to make
         # our parent
         if ($parentFolder === null) {
             throw new Exception("error set path resulted in a null parent folder");
         }
         print PHP_EOL;
         print "SETPATH {$path}: setting parent folder" . PHP_EOL;
         $this->setParentFolder($parentFolder);
         $this->updateField('path', $path);
     } else {
     }
     return $this;
 }