class FileSystemTarget implements TargetInterface (View source)

A target which publishes resources to a specific directory in a file system.

Properties

protected array $options
protected string $name

Name which identifies this publishing target

protected $callbacks
protected string $path

The path (in a filesystem) where resources are published to

protected string $baseUri

The configured publicly accessible web URI which points to the root path of this target.

protected string $absoluteBaseUri

The resolved absolute web URI for this target. If $baseUri was absolute this will be the same, otherwise the request base uri will be prepended.

protected bool $subdivideHashPathSegment

If the generated URI path segment containing the sha1 should be divided into multiple segments

protected array $excludedExtensions

A list of extensions that are excluded and must not be published by this target.

protected ResourceRepository $resourceRepository
protected LoggerInterface $logger
protected MessageCollector $messageCollector
protected BaseUriProvider $baseUriProvider

Methods

__construct(string $name, array $options = [])

Constructor

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

void
initializeObject()

Initializes this resource publishing target

string
getName()

Returns the name of this target instance

void
onPublish(Closure $callback)

No description

void
invokeOnPublishCallbacks(int $iteration)

No description

void
checkAndRemovePackageSymlinks(StorageInterface $storage)

Checks if the PackageStorage has been previously initialized with symlinks and clears them. Otherwise the original sources would be overwritten.

void
publishCollection(CollectionInterface $collection)

Publishes the whole collection to this target

void
publishResource(PersistentResource $resource, CollectionInterface $collection)

Publishes the given persistent resource from the given storage

handleMissingData(ResourceMetaDataInterface $resource, CollectionInterface $collection)

Handle missing data notification

void
unpublishResource(PersistentResource $resource)

Unpublishes the given persistent resource

string
getPublicStaticResourceUri(string $relativePathAndFilename)

Returns the web accessible URI pointing to the given static resource

string
getPublicPersistentResourceUri(PersistentResource $resource)

Returns the web accessible URI pointing to the specified persistent resource

string
encodeRelativePathAndFilenameForUri(string $relativePathAndFilename)

Applies rawurlencode() to all path segments of the given $relativePathAndFilename

void
publishFile(resource $sourceStream, string $relativeTargetPathAndFilename)

Publishes the given source stream to this target, with the given relative path.

void
unpublishFile(string $relativeTargetPathAndFilename)

Removes the specified target file from the public directory

string
getResourcesBaseUri()

Returns the resolved absolute base URI for resources of this target.

string
detectResourcesBaseUri()

Detects and returns the website's absolute base URI

string
getRelativePublicationPathAndFilename(ResourceMetaDataInterface $object)

Determines and returns the relative path and filename for the given Storage Object or PersistentResource. If the given object represents a persistent resource, its own relative publication path will be empty. If the given object represents a static resources, it will contain a relative path.

bool
setOption(string $key, mixed $value)

Set an option value and return if it was set.

Details

__construct(string $name, array $options = [])

Constructor

Parameters

string $name

Name of this target instance, according to the resource settings

array $options

Options for this target

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

void initializeObject()

Initializes this resource publishing target

Return Value

void

Exceptions

Exception

string getName()

Returns the name of this target instance

Return Value

string

void onPublish(Closure $callback)

No description

Parameters

Closure $callback

Return Value

void

protected void invokeOnPublishCallbacks(int $iteration)

No description

Parameters

int $iteration

Return Value

void

Checks if the PackageStorage has been previously initialized with symlinks and clears them. Otherwise the original sources would be overwritten.

Parameters

StorageInterface $storage

Return Value

void

void publishCollection(CollectionInterface $collection)

Publishes the whole collection to this target

Parameters

CollectionInterface $collection

The collection to publish

Return Value

void

void publishResource(PersistentResource $resource, CollectionInterface $collection)

Publishes the given persistent resource from the given storage

Parameters

PersistentResource $resource

The resource to publish

CollectionInterface $collection

The collection the given resource belongs to

Return Value

void

protected handleMissingData(ResourceMetaDataInterface $resource, CollectionInterface $collection)

Handle missing data notification

Parameters

ResourceMetaDataInterface $resource
CollectionInterface $collection

void unpublishResource(PersistentResource $resource)

Unpublishes the given persistent resource

Parameters

PersistentResource $resource

The resource to unpublish

Return Value

void

string getPublicStaticResourceUri(string $relativePathAndFilename)

Returns the web accessible URI pointing to the given static resource

Parameters

string $relativePathAndFilename

Relative path and filename of the static resource

Return Value

string

The URI

string getPublicPersistentResourceUri(PersistentResource $resource)

Returns the web accessible URI pointing to the specified persistent resource

Parameters

PersistentResource $resource

PersistentResource object

Return Value

string

The URI

Exceptions

Exception

protected string encodeRelativePathAndFilenameForUri(string $relativePathAndFilename)

Applies rawurlencode() to all path segments of the given $relativePathAndFilename

Parameters

string $relativePathAndFilename

Return Value

string

protected void publishFile(resource $sourceStream, string $relativeTargetPathAndFilename)

Publishes the given source stream to this target, with the given relative path.

Parameters

resource $sourceStream

Stream of the source to publish

string $relativeTargetPathAndFilename

relative path and filename in the target directory

Return Value

void

Exceptions

Exception

protected void unpublishFile(string $relativeTargetPathAndFilename)

Removes the specified target file from the public directory

This method fails silently if the given file could not be unpublished or already didn't exist anymore.

Parameters

string $relativeTargetPathAndFilename

relative path and filename in the target directory

Return Value

void

protected string getResourcesBaseUri()

Returns the resolved absolute base URI for resources of this target.

Return Value

string

The absolute base URI for resources in this target

protected string detectResourcesBaseUri()

Detects and returns the website's absolute base URI

Return Value

string

The resolved resource base URI, getResourcesBaseUri()

Exceptions

Exception

protected string getRelativePublicationPathAndFilename(ResourceMetaDataInterface $object)

Determines and returns the relative path and filename for the given Storage Object or PersistentResource. If the given object represents a persistent resource, its own relative publication path will be empty. If the given object represents a static resources, it will contain a relative path.

No matter which kind of resource, persistent or static, this function will return a sub directory structure if no relative publication path was defined in the given object.

Parameters

ResourceMetaDataInterface $object

PersistentResource or Storage Object

Return Value

string

The relative path and filename, for example "c/8/2/8/c828d0f88ce197be1aff7cc2e5e86b1244241ac6/MyPicture.jpg" (if subdivideHashPathSegment is on) or "c828d0f88ce197be1aff7cc2e5e86b1244241ac6/MyPicture.jpg" (if it's off)

protected bool setOption(string $key, mixed $value)

Set an option value and return if it was set.

Parameters

string $key
mixed $value

Return Value

bool