Final Class Yiisoft\Assets\AssetRegistrar
| Inheritance | Yiisoft\ |
|---|
AssetRegistrar registers asset files, code blocks and variables from a bundle considering dependencies.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getCssFiles() | Yiisoft\ |
|
| getCssStrings() | Yiisoft\ |
|
| getJsFiles() | Yiisoft\ |
|
| getJsStrings() | Yiisoft\ |
|
| getJsVars() | Yiisoft\ |
|
| register() | Registers assets from a bundle considering dependencies. | Yiisoft\ |
| withConverter() | Yiisoft\ |
|
| withLoader() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $aliases | \ |
|
| $loader | Yiisoft\ |
|
public function __construct(
private Aliases $aliases,
private AssetLoaderInterface $loader,
) {}
| public array getCssFiles ( ) | ||
| return | array |
Config array of CSS files. |
|---|---|---|
public function getCssFiles(): array
{
return $this->cssFiles;
}
| public array getCssStrings ( ) | ||
| return | array |
CSS blocks. |
|---|---|---|
public function getCssStrings(): array
{
return $this->cssStrings;
}
| public array getJsFiles ( ) | ||
| return | array |
Config array of JavaScript files. |
|---|---|---|
public function getJsFiles(): array
{
return $this->jsFiles;
}
| public array getJsStrings ( ) | ||
| return | array |
JavaScript code blocks. |
|---|---|---|
public function getJsStrings(): array
{
return $this->jsStrings;
}
| public array getJsVars ( ) | ||
| return | array |
JavaScript variables. |
|---|---|---|
public function getJsVars(): array
{
return array_values($this->jsVars);
}
Registers assets from a bundle considering dependencies.
| public void register ( Yiisoft\ | ||
| $bundle | Yiisoft\ |
|
| throws | Yiisoft\ |
If asset files are not found. |
|---|---|---|
public function register(AssetBundle $bundle): void
{
if (isset($bundle->basePath, $bundle->baseUrl) && $this->converter !== null) {
$this->convertCss($bundle);
$this->convertJs($bundle);
}
/** @var JsFile|string $js */
foreach ($bundle->js as $key => $js) {
$this->registerJsFile(
$bundle,
is_string($key) ? $key : null,
$js,
);
}
foreach ($bundle->jsStrings as $key => $jsString) {
$this->registerJsString(
$bundle,
is_string($key) ? $key : null,
$jsString,
);
}
/** @var JsVar|string $jsVar */
foreach ($bundle->jsVars as $name => $jsVar) {
if (is_string($name)) {
$this->registerJsVar($name, $jsVar, $bundle->jsPosition);
} else {
$this->registerJsVarByConfig($jsVar, $bundle->jsPosition);
}
}
/** @var CssFile|string $css */
foreach ($bundle->css as $key => $css) {
$this->registerCssFile(
$bundle,
is_string($key) ? $key : null,
$css,
);
}
foreach ($bundle->cssStrings as $key => $cssString) {
$this->registerCssString(
$bundle,
is_string($key) ? $key : null,
$cssString,
);
}
}
| public self withConverter ( Yiisoft\ | ||
| $converter | Yiisoft\ |
|
| return | self |
A new instance with the specified converter. |
|---|---|---|
public function withConverter(AssetConverterInterface $converter): self
{
$new = clone $this;
$new->converter = $converter;
return $new;
}
| public self withLoader ( Yiisoft\ | ||
| $loader | Yiisoft\ |
|
| return | self |
A new instance with the specified loader. |
|---|---|---|
public function withLoader(AssetLoaderInterface $loader): self
{
$new = clone $this;
$new->loader = $loader;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.