Resources can be read using their absolute file system paths: php use Puli\Repository\FilesystemRepository; $repo = new FilesystemRepository(); $resource = $repo->get('/home/puli/.gitconfig'); The returned resources implement {@link FilesystemResource}. Optionally, a root directory can be passed to the constructor. Then all paths will be read relative to that directory: php $repo = new FilesystemRepository('/home/puli'); $resource = $repo->get('/.gitconfig'); While "." and ".." segments are supported, files outside the root directory cannot be read. Any leading ".." segments will simply be stripped off.
Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Inheritance: implements Puli\Repository\Api\EditableRepository
Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function installResource(Resource $resource, InstallationParams $params)
 {
     $targetPath = Path::makeAbsolute($params->getTargetLocation(), $params->getRootDirectory());
     if (!file_exists($targetPath)) {
         mkdir($targetPath, 0777, true);
     }
     $repoPath = $params->getWebPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($targetPath, $this->symlinks, $relative);
     if ('/' === $repoPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($repoPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($repoPath);
     }
     $filesystemRepo->add($repoPath, $resource);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function installResource(PuliResource $resource, InstallationParams $params)
 {
     $documentRoot = Path::makeAbsolute($params->getDocumentRoot(), $params->getRootDirectory());
     if (!file_exists($documentRoot)) {
         mkdir($documentRoot, 0777, true);
     }
     $serverPath = $params->getServerPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($documentRoot, $this->symlinks, $relative);
     if ('/' === $serverPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($serverPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($serverPath);
     }
     // Don't attach the original resource to the repository we just created
     $filesystemRepo->add($serverPath, clone $resource);
 }
 protected function createRepository(Resource $root)
 {
     $repo = new FilesystemRepository($this->tempDir, true, false);
     $repo->add('/', $root);
     return $repo;
 }
 /**
  * @expectedException \Puli\Repository\Api\UnsupportedLanguageException
  * @expectedExceptionMessage foobar
  */
 public function testFindFailsIfLanguageNotGlob()
 {
     $repo = new FilesystemRepository($this->tempDir);
     $repo->find('/*', 'foobar');
 }