getFolderTreeFromUserRoot() public method

 /**
  * Store a new document.
  *
  * @returns an array of all created objects
  */
 public function putDocument(Path $p, $documentContent)
 {
     $folderTree = $p->getFolderTreeFromUserRoot();
     foreach ($folderTree as $pathItem) {
         $folderPath = $this->baseDir . $pathItem;
         $folderPathAsFile = substr($folderPath, 0, strlen($folderPath) - 1);
         if (file_exists($folderPathAsFile) && is_file($folderPathAsFile)) {
             throw new ConflictException('file already exists in path preventing folder creation');
         }
         if (!file_exists($folderPath)) {
             // create it
             if (false === @mkdir($this->baseDir . $pathItem, 0770)) {
                 throw new DocumentStorageException('unable to create directory');
             }
         }
     }
     $documentPath = $this->baseDir . $p->getPath();
     if (file_exists($documentPath) && is_dir($documentPath)) {
         throw new ConflictException('document path is already a folder');
     }
     if (false === @file_put_contents($documentPath, $documentContent)) {
         throw new DocumentStorageException('unable to write document');
     }
     // PHP caches files and doesn't flush on getting file size, so we
     // really have to flush the cache manually, otherwise directory listings
     // potentially give you the wrong information. This only affects the
     // unit tests, as getting a directory listing and putting a file are
     // always separate script executions
     clearstatcache(true, $documentPath);
     return $folderTree;
 }
Beispiel #2
0
 public function testShortPathTreeFromUserRoot()
 {
     $path = new Path('/foo/bar');
     $this->assertEquals(array('/foo/'), $path->getFolderTreeFromUserRoot());
 }