public function testGetFileLink()
 {
     touch($this->tempDir . '/file');
     symlink($this->tempDir . '/file', $this->tempDir . '/link');
     $repo = new FilesystemRepository($this->tempDir);
     $expected = new FileResource($this->tempDir . '/link', '/link');
     $expected->attachTo($repo);
     $this->assertEquals($expected, $repo->get('/link'));
 }
Esempio n. 2
0
 /**
  * Turns a reference into a resource.
  *
  * @param string      $path      The Puli path.
  * @param string|null $reference The reference.
  *
  * @return PuliResource The resource.
  */
 protected function createResource($path, $reference)
 {
     if (null === $reference) {
         $resource = new GenericResource();
     } elseif (isset($reference[0]) && '@' === $reference[0]) {
         $resource = new LinkResource(substr($reference, 1));
     } elseif (is_dir($reference)) {
         $resource = new DirectoryResource($reference);
     } elseif (is_file($reference)) {
         $resource = new FileResource($reference);
     } else {
         throw new RuntimeException(sprintf('Trying to create a FilesystemResource on a non-existing file or directory "%s"', $reference));
     }
     $resource->attachTo($this, $path);
     return $resource;
 }
 public function testHasChildrenWithReference()
 {
     $repo = $this->getMock('Puli\\Repository\\Api\\ResourceRepository');
     $repo->expects($this->never())->method('hasChildren');
     $resource = new FileResource($this->fixturesDir . '/dir1/file1');
     $resource->attachTo($repo);
     $reference = $resource->createReference('/reference');
     $this->assertFalse($reference->hasChildren());
 }
Esempio n. 4
0
 private function createResource($filesystemPath, $path)
 {
     $resource = null;
     if (is_link($filesystemPath)) {
         $baseDir = rtrim($this->baseDir, '/');
         $targetFilesystemPath = $this->readLink($filesystemPath);
         if (Path::isBasePath($baseDir, $targetFilesystemPath)) {
             $targetPath = '/' . Path::makeRelative($targetFilesystemPath, $baseDir);
             $resource = new LinkResource($targetPath);
         }
     }
     if (!$resource && is_dir($filesystemPath)) {
         $resource = new DirectoryResource($filesystemPath);
     }
     if (!$resource) {
         $resource = new FileResource($filesystemPath);
     }
     $resource->attachTo($this, $path);
     return $resource;
 }