PHP Interface Puli\Repository\Api\Resource\PuliResource

Resources are objects which can be stored in a resource repository. Resources have a path, under which they are stored in the repository. Depending on the implementation, resources may offer additional functionality: * Resources that are similar to files in that they have a body and a size should implement {@link BodyResource}. Resources can be attached to a repository by calling {@link attachTo()}. They can be detached again by calling {@link detach()}. Use {@link isAttached()} to find out whether a resource is attached and {@link getRepository()} to obtain the attached repository. You can create a reference to a resource by calling {@link createReference()}. References can have different paths than the resource they are referencing. Otherwise, they are identical to the referenced resource. Use {@link isReference()} to check whether a resource is a reference. You can call {@link getRepositoryPath()} to retrieve the path of the referenced resource. If you implement a custom resource, let your test extend {@link AbstractResourceTest} to make sure your resource satisfies the constraints of the interface. Extend {@link GenericResource} if you want to avoid reimplementing basic functionality.
Since: 1.0
Author: Bernhard Schussek ([email protected])
Inheritance: extends Serializabl\Serializable
ファイルを表示 Open project: puli/repository Interface Usage Examples

Public Methods

Method Description
attachTo ( Puli\Repository\Api\ResourceRepository $repo, string | null $path = null ) Attaches the resource to a repository.
createReference ( string $path ) : static Creates a reference to the resource.
detach ( ) Detaches the resource from the repository.
getChild ( string $relPath ) : Puli\Repository\Api\Resource\PuliResource Returns the child resource with the given relative path.
getMetadata ( ) : ResourceMetadata Returns metadata about a resource.
getName ( ) : string | null Returns the name of the resource.
getPath ( ) : string | null Returns the path of the resource.
getRepository ( ) : Puli\Repository\Api\ResourceRepository | null Returns the repository that the resource is attached to.
getRepositoryPath ( ) : string | null Returns the path of the resource in the repository.
getVersions ( ) : VersionList Returns the versions of this resource.
hasChild ( string $relPath ) : boolean Returns whether the child resource with the given relative path exists.
hasChildren ( ) : boolean Returns whether the resource has child resources.
isAttached ( ) : boolean Returns whether the resource is attached to a repository.
isReference ( ) : boolean Returns whether a resource is a reference.
listChildren ( ) : Puli\Repository\Api\ResourceCollection Lists the child resources of the resources.

Method Details

attachTo() public method

You can optionally change the path of the resource by passing it in the second argument. Beware that this may break the resource if it is still referenced by another repository. Hence you should clone resources that are attached to another repository before attaching them: php if ($resource->isAttached()) { $resource = clone $resource; } $resource->attachTo($repo, '/path/in/repo');
public attachTo ( Puli\Repository\Api\ResourceRepository $repo, string | null $path = null )
$repo Puli\Repository\Api\ResourceRepository The repository.
$path string | null The path of the resource in the repository. If not passed, the resource will be attached to it current path.

createReference() public method

References are identical for their referenced resource except for their path. The path of the referenced resource can be obtained by calling {@link getRepositoryPath()}: php $resource = new MyResource('/path'); $reference = $resource->createReference('/reference'); $reference->getPath(); "/reference" $reference->getRepositoryPath(); "/path" Use {@link isReference()} to find out whether a resource is a reference.
public createReference ( string $path ) : static
$path string The path of the reference.
return static The reference.

detach() public method

After calling this method, {@link isAttached()} returns false. The method {@link getRepository()} should return null after detaching. Neither the path nor the repository path of the resource should be modified when detaching.
public detach ( )

getChild() public method

"." and ".." are supported as paths.
public getChild ( string $relPath ) : Puli\Repository\Api\Resource\PuliResource
$relPath string The relative resource path.
return Puli\Repository\Api\Resource\PuliResource The resource with the given path.

getMetadata() public method

Returns metadata about a resource.
public getMetadata ( ) : ResourceMetadata
return ResourceMetadata The resource metadata.

getName() public method

The name is the last segment of the path returned by {@link getPath()}.
public getName ( ) : string | null
return string | null The name of the resource. If the resource has no path, `null` is returned.

getPath() public method

For references created with {@link createReference()}, the path returned by this method is the reference path and not the actual repository path of the referenced resource. You should use {@link getRepositoryPath()} if you want to glob the repository for a resource.
public getPath ( ) : string | null
return string | null The path of the resource. If the resource has no path, `null` is returned.

getRepository() public method

Use {@link attachTo()} to attach a resource to a repository. The method {@link detach()} can be used to detach an attached resource.
public getRepository ( ) : Puli\Repository\Api\ResourceRepository | null
return Puli\Repository\Api\ResourceRepository | null The resource repository. If the resource is not attached to any repository, `null` is returned.

getRepositoryPath() public method

The repository path is the path that the resource is mapped to once attached to a repository. The result of this method is different from {@link getPath()} for resource references. PuliResource references return the path of the referenced resource here, while {@link getPath()} returns the path of the reference itself.
public getRepositoryPath ( ) : string | null
return string | null The repository path of the resource. If the resource has no repository path, `null` is returned.

getVersions() public method

Returns the versions of this resource.
public getVersions ( ) : VersionList
return Puli\Repository\Api\ChangeStream\VersionList The resource versions.

hasChild() public method

Returns whether the child resource with the given relative path exists.
public hasChild ( string $relPath ) : boolean
$relPath string The relative resource path.
return boolean Whether a resource with the given path exists.

hasChildren() public method

Returns whether the resource has child resources.
public hasChildren ( ) : boolean
return boolean Returns `true` if the resource has child resources.

isAttached() public method

Resources can be attached to a repository with {@link attachTo()}. The method {@link getRepository()} returns the attached repository.
public isAttached ( ) : boolean
return boolean Whether the resource is attached to a repository.

isReference() public method

References are created by calling {@link createReference()}.
public isReference ( ) : boolean
return boolean Whether the resource is a reference.

listChildren() public method

Lists the child resources of the resources.
public listChildren ( ) : Puli\Repository\Api\ResourceCollection
return Puli\Repository\Api\ResourceCollection The child resources indexed by their names.