Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter only not working #143

Open
BaBL86 opened this issue Jun 16, 2024 · 2 comments
Open

Filter only not working #143

BaBL86 opened this issue Jun 16, 2024 · 2 comments
Labels
type:docs Documentation

Comments

@BaBL86
Copy link

BaBL86 commented Jun 16, 2024

According to documentation I add $publishOptions['only'] in my project, but it doesn't work

What steps will reproduce the problem?

class BootstrapAsset extends AssetBundle
{
    public ?string $basePath = '@assets';

    public ?string $baseUrl = '@assetsUrl';

    public ?string $sourcePath = '@assetsPath/bootstrap';

    public array $css = [
        'css/bootstrap.min.css',
    ];

    public array $js = [
        'js/bootstrap.bundle.min.js',
    ];

    public array $depends = [
        \App\Assets\JqueryAsset::class,
    ];

    public array $publishOptions = [
        'only' => [
            'css/bootstrap.min.css',
            'js/bootstrap.bundle.min.js',
        ]
    ];
}

What is the expected result?

I expect to have only 2 files in published assets, but I have full bootstrap library like in

ea9e2702
- css
- - bootstrap.min.css
- js
- - bootstrap.bundle.min.js

What do you get instead?

ea9e2702
- css
- - bootstrap.css
- - bootstrap.min.css
- - bootstrap.rtl.css
- - bootstrap-grid.css
- - bootstrap-grid.rtl.css
- - bootstrap-reboot.css
- - bootstrap-reboot.rtl.css
- - bootstrap-utilities.css
- - bootstrap-utilities.rtl.css
- js
- - bootstrap.bundle.js
- - bootstrap.bundle.min.js
- - bootstrap.esm.js
- - bootstrap.js

Workaround

This code works like a charm, but it's not comfort and documentation have another way.

    public function __construct()
    {
        $pathMatcher = new PathMatcher();

        $filters = [];
        foreach ($this->css as $file)
            $filters[] = '**/' . $file;
        foreach ($this->js as $file)
            $filters[] = '**/' . $file;

        $this->publishOptions = [
            'filter' => $pathMatcher->only(...$filters),
        ];
    }

Additional info

Q A
Version 4.0.0
PHP version 8.3
Operating system Debian GNU/Linux
@BaBL86
Copy link
Author

BaBL86 commented Jun 16, 2024

@vjik
Copy link
Member

vjik commented Jun 16, 2024

Instead only need to use filter option, that use PathMatcherInterface. Need to fix docs.

@vjik vjik added the type:docs Documentation label Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Documentation
Projects
None yet
Development

No branches or pull requests

2 participants