0 follower

Final Class Yiisoft\Assets\AssetRegistrar

InheritanceYiisoft\Assets\AssetRegistrar

AssetRegistrar registers asset files, code blocks and variables from a bundle considering dependencies.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Aliases\Aliases $aliases, Yiisoft\Assets\AssetLoaderInterface $loader )
$aliases \Yiisoft\Aliases\Aliases
$loader Yiisoft\Assets\AssetLoaderInterface

                public function __construct(
    private Aliases $aliases,
    private AssetLoaderInterface $loader
) {
}

            
getCssFiles() public method

public array getCssFiles ( )
return array

Config array of CSS files.

                public function getCssFiles(): array
{
    return $this->cssFiles;
}

            
getCssStrings() public method

public array getCssStrings ( )
return array

CSS blocks.

                public function getCssStrings(): array
{
    return $this->cssStrings;
}

            
getJsFiles() public method

public array getJsFiles ( )
return array

Config array of JavaScript files.

                public function getJsFiles(): array
{
    return $this->jsFiles;
}

            
getJsStrings() public method

public array getJsStrings ( )
return array

JavaScript code blocks.

                public function getJsStrings(): array
{
    return $this->jsStrings;
}

            
getJsVars() public method

public array getJsVars ( )
return array

JavaScript variables.

                public function getJsVars(): array
{
    return array_values($this->jsVars);
}

            
register() public method

Registers assets from a bundle considering dependencies.

public void register ( Yiisoft\Assets\AssetBundle $bundle )
$bundle Yiisoft\Assets\AssetBundle
throws Yiisoft\Assets\Exception\InvalidConfigException

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,
        );
    }
}

            
withConverter() public method

public self withConverter ( Yiisoft\Assets\AssetConverterInterface $converter )
$converter Yiisoft\Assets\AssetConverterInterface
return self

A new instance with the specified converter.

                public function withConverter(AssetConverterInterface $converter): self
{
    $new = clone $this;
    $new->converter = $converter;
    return $new;
}

            
withLoader() public method

public self withLoader ( Yiisoft\Assets\AssetLoaderInterface $loader )
$loader Yiisoft\Assets\AssetLoaderInterface
return self

A new instance with the specified loader.

                public function withLoader(AssetLoaderInterface $loader): self
{
    $new = clone $this;
    $new->loader = $loader;
    return $new;
}