Final Class Yiisoft\Assets\AssetPublisher
| Inheritance | Yiisoft\Assets\AssetPublisher |
|---|---|
| Implements | Yiisoft\Assets\AssetPublisherInterface |
AssetPublisher is responsible for executing the publication of the assets from {@see AssetBundle::$sourcePath} to
{@see AssetBundle::$basePath}.
Psalm Types
| Name | Value |
|---|---|
| HashCallback | callable |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Assets\AssetPublisher | |
| getPublishedPath() | Yiisoft\Assets\AssetPublisher | |
| getPublishedUrl() | Yiisoft\Assets\AssetPublisher | |
| publish() | Yiisoft\Assets\AssetPublisher | |
| withDirMode() | Returns a new instance with the specified directory mode. | Yiisoft\Assets\AssetPublisher |
| withFileMode() | Returns a new instance with the specified files mode. | Yiisoft\Assets\AssetPublisher |
| withForceCopy() | Returns a new instance with the specified force copy value. | Yiisoft\Assets\AssetPublisher |
| withHashCallback() | Returns a new instance with the specified force hash callback. | Yiisoft\Assets\AssetPublisher |
| withLinkAssets() | Returns a new instance with the specified link assets value. | Yiisoft\Assets\AssetPublisher |
Method Details
| public mixed __construct ( \Yiisoft\Aliases\Aliases $aliases, boolean $forceCopy = false, boolean $linkAssets = false ) | ||
| $aliases | \Yiisoft\Aliases\Aliases |
The aliases instance. |
| $forceCopy | boolean |
Whether the directory being published should be copied even if it is found in the target directory. See {@see \Yiisoft\Assets\withForceCopy()}. |
| $linkAssets | boolean |
Whether to use symbolic link to publish asset files. See {@see \Yiisoft\Assets\withLinkAssets()}. |
public function __construct(
private readonly Aliases $aliases,
private bool $forceCopy = false,
private bool $linkAssets = false,
) {
}
| public string|null getPublishedPath ( string $sourcePath ) | ||
| $sourcePath | string | |
public function getPublishedPath(string $sourcePath): ?string
{
$sourcePath = $this->aliases->get($sourcePath);
if (isset($this->published[$sourcePath])) {
return $this->published[$sourcePath][0];
}
return null;
}
| public string|null getPublishedUrl ( string $sourcePath ) | ||
| $sourcePath | string | |
public function getPublishedUrl(string $sourcePath): ?string
{
$sourcePath = $this->aliases->get($sourcePath);
if (isset($this->published[$sourcePath])) {
return $this->published[$sourcePath][1];
}
return null;
}
| public array publish ( Yiisoft\Assets\AssetBundle $bundle ) | ||
| $bundle | Yiisoft\Assets\AssetBundle | |
public function publish(AssetBundle $bundle): array
{
if (empty($bundle->sourcePath)) {
throw new InvalidConfigException(
'The sourcePath must be defined in AssetBundle property public ?string $sourcePath = $path.',
);
}
$sourcePath = $this->aliases->get($bundle->sourcePath);
if (isset($this->published[$sourcePath])) {
return $this->published[$sourcePath];
}
if (empty($bundle->basePath)) {
throw new InvalidConfigException(
'The basePath must be defined in AssetBundle property public ?string $basePath = $path.',
);
}
if ($bundle->baseUrl === null) {
throw new InvalidConfigException(
'The baseUrl must be defined in AssetBundle property public ?string $baseUrl = $path.',
);
}
if (!file_exists($sourcePath)) {
throw new InvalidConfigException("The sourcePath to be published does not exist: {$sourcePath}");
}
return $this->published[$sourcePath] = $this->publishBundleDirectory($bundle);
}
Returns a new instance with the specified directory mode.
| public self withDirMode ( integer $dirMode ) | ||
| $dirMode | integer |
The permission to be set for newly generated asset directories. This value will be used
by PHP |
public function withDirMode(int $dirMode): self
{
$new = clone $this;
$new->dirMode = $dirMode;
return $new;
}
Returns a new instance with the specified files mode.
| public self withFileMode ( integer $fileMode ) | ||
| $fileMode | integer |
He permission to be set for newly published asset files. This value will be used
by PHP |
public function withFileMode(int $fileMode): self
{
$new = clone $this;
$new->fileMode = $fileMode;
return $new;
}
Returns a new instance with the specified force copy value.
| public self withForceCopy ( boolean $forceCopy ) | ||
| $forceCopy | boolean |
Whether the directory being published should be copied even if it is found in the target
directory. This option is used only when publishing a directory. You may want to set this to be |
public function withForceCopy(bool $forceCopy): self
{
$new = clone $this;
$new->forceCopy = $forceCopy;
return $new;
}
Returns a new instance with the specified force hash callback.
| public self withHashCallback ( callable $hashCallback ) | ||
| $hashCallback | callable |
A callback that will be called to produce hash for asset directory generation. The signature of the callback should be as follows:
Where If this is not set, the asset manager will use the default CRC32 and filemtime in the Example of an implementation using MD4 hash:
|
public function withHashCallback(callable $hashCallback): self
{
$new = clone $this;
$new->hashCallback = $hashCallback;
return $new;
}
Returns a new instance with the specified link assets value.
| public self withLinkAssets ( boolean $linkAssets ) | ||
| $linkAssets | boolean |
Whether to use symbolic link to publish asset files. Default is However, there are special requirements for hosting environments in order to use symbolic links. In particular, symbolic links are supported only on Linux/Unix, and Windows Vista/2008 or greater. Moreover, some Web servers need to be properly configured so that the linked assets are accessible to Web users. For example, for Apache Web server, the following configuration directive should be added for the Web folder:
|
public function withLinkAssets(bool $linkAssets): self
{
$new = clone $this;
$new->linkAssets = $linkAssets;
return $new;
}
Signup or Login in order to comment.