fkooman\RemoteStorage\DocumentStorage::getFolder PHP Method

getFolder() public method

public getFolder ( Path $p )
$p Path
    public function getFolder(Path $p)
    {
        $folderPath = $this->baseDir . $p->getPath();
        $entries = glob($folderPath . '*', GLOB_ERR | GLOB_MARK);
        if (false === $entries) {
            // directory does not exist, return empty list
            return array();
        }
        $folderEntries = array();
        foreach ($entries as $e) {
            if (is_dir($e)) {
                $folderEntries[basename($e) . '/'] = array();
            } else {
                $folderEntries[basename($e)] = array('Content-Length' => filesize($e));
            }
        }
        return $folderEntries;
    }

Usage Example

 public function getFolder(Path $p, array $ifNoneMatch = null)
 {
     if (null !== $ifNoneMatch && in_array($this->md->getVersion($p), $ifNoneMatch)) {
         throw new RemoteStorageException('folder not modified');
     }
     $f = array('@context' => 'http://remotestorage.io/spec/folder-description', 'items' => $this->d->getFolder($p));
     foreach ($f['items'] as $name => $meta) {
         $f['items'][$name]['ETag'] = $this->md->getVersion(new Path($p->getFolderPath() . $name));
         // if item is a folder we don't want Content-Type
         if (strrpos($name, '/') !== strlen($name) - 1) {
             $f['items'][$name]['Content-Type'] = $this->md->getContentType(new Path($p->getFolderPath() . $name));
         }
     }
     return Json::encode($f, JSON_FORCE_OBJECT);
 }