Puli\Repository\AbstractJsonRepository::createResource PHP Method

createResource() protected method

Turns a reference into a resource.
protected createResource ( string $path, string | null $reference ) : Puli\Repository\Api\Resource\PuliResource
$path string The Puli path.
$reference string | null The reference.
return Puli\Repository\Api\Resource\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;
    }