fkooman\RemoteStorage\RemoteStorage::getFolder PHP Method

getFolder() public method

public getFolder ( Path $p, array $ifNoneMatch = null )
$p Path
$ifNoneMatch array
    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);
    }

Usage Example

 public function getFolder(Path $path, Request $request, TokenInfo $tokenInfo)
 {
     if ($path->getUserId() !== $tokenInfo->getUserId()) {
         throw new ForbiddenException('path does not match authorized subject');
     }
     if (!$this->hasReadScope($tokenInfo->getScope(), $path->getModuleName())) {
         throw new ForbiddenException('path does not match authorized scope');
     }
     $folderVersion = $this->remoteStorage->getVersion($path);
     if (null === $folderVersion) {
         // folder does not exist, so we just invent this
         // ETag that will be the same for all empty folders
         $folderVersion = 'e:404';
     }
     $requestedVersion = $this->stripQuotes($request->getHeader('If-None-Match'));
     if (null !== $requestedVersion) {
         if (in_array($folderVersion, $requestedVersion)) {
             //return new RemoteStorageResponse($request, 304, $folderVersion);
             $response = new Response(304, 'application/ld+json');
             $response->setHeader('ETag', '"' . $folderVersion . '"');
             return $response;
         }
     }
     $rsr = new Response(200, 'application/ld+json');
     $rsr->setHeader('ETag', '"' . $folderVersion . '"');
     if ('GET' === $request->getMethod()) {
         $rsr->setBody($this->remoteStorage->getFolder($path, $this->stripQuotes($request->getHeader('If-None-Match'))));
     }
     return $rsr;
 }