Puli\Repository\Resource\DirectoryResource::getChild PHP Method

getChild() public method

public getChild ( $relPath )
    public function getChild($relPath)
    {
        // Use attached repository if possible
        if ($this->getRepository()) {
            return $this->getRepository()->get($this->getRepositoryPath() . '/' . $relPath);
        }
        $filesystemPath = $this->getFilesystemPath() . '/' . $relPath;
        if (!file_exists($filesystemPath)) {
            throw ResourceNotFoundException::forPath($this->getPath() . '/' . $relPath);
        }
        $childPath = null === $this->getPath() ? null : $this->getPath() . '/' . $relPath;
        return is_dir($filesystemPath) ? new self($filesystemPath, $childPath) : new FileResource($filesystemPath, $childPath);
    }

Usage Example

 public function testGetChildDetached()
 {
     $resource = new DirectoryResource($this->fixturesDir . '/dir1');
     $this->assertEquals(new FileResource($this->fixturesDir . '/dir1/file1'), $resource->getChild('file1'));
 }