Final Class Yiisoft\Assets\AssetPublisher
| Inheritance | Yiisoft\Assets\AssetPublisher |
|---|---|
| Implements | Yiisoft\Assets\AssetPublisherInterface |
AssetPublisher is responsible for executing the publication of the assets from Yiisoft\Assets\AssetBundle::$sourcePath to
Yiisoft\Assets\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 __construct( \Yiisoft\Aliases\Aliases $aliases, boolean $forceCopy = false, boolean $linkAssets = false ): mixed | ||
| $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 withForceCopy(). |
| $linkAssets | boolean |
Whether to use symbolic link to publish asset files. See withLinkAssets(). |
public function __construct(
private readonly Aliases $aliases,
private bool $forceCopy = false,
private bool $linkAssets = false,
) {}
| public getPublishedPath( string $sourcePath ): string|null | ||
| $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 getPublishedUrl( string $sourcePath ): string|null | ||
| $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 publish( Yiisoft\Assets\AssetBundle $bundle ): array | ||
| $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 withDirMode( integer $dirMode ): self | ||
| $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 withFileMode( integer $fileMode ): self | ||
| $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 withForceCopy( boolean $forceCopy ): self | ||
| $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 withHashCallback( callable $hashCallback ): self | ||
| $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 withLinkAssets( boolean $linkAssets ): self | ||
| $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.