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')); }
public function testGetFilesystemPathsIgnoresResourcesWithEmptyFilesystemPaths() { $collection = new FilesystemResourceCollection(array($dir = new DirectoryResource($this->fixturesDir . '/dir1'), $file = new FileResource($this->fixturesDir . '/file3'), $this->getMock('Puli\\Repository\\Api\\Resource\\FilesystemResource'))); $this->assertSame(array($dir->getFilesystemPath(), $file->getFilesystemPath()), $collection->getFilesystemPaths()); }
/** * 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 testHasChildrenDetached() { $resource = new FileResource($this->fixturesDir . '/dir1/file1'); $this->assertFalse($resource->hasChildren()); }
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; }