Skip to content

Alias for each assets package #30645

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

Merged

Conversation

gpenverne
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? ?
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Add autowiring by type + name on assets packages

framework:
    assets:
        packages:
            xxx:
                base_urls: 'xxxx'
<?php

class MyService 
{
    private $xxxPackage;

    public function __construct(PackageInterface $xxxPackage) 
    {
        $this->xxxPackage = $xxxPackage;
        ...
    }

    public function myMethod(): string
    {
        return $this->xxxPackage->getUrl('some-image.png');
    }
}

instead of:

<?php

class MyService 
{
    private $packages;

    public function __construct(Packages $packages) 
    {
        $this->packages = $packages;
        ...
    }

    public function myMethod(): string
    {
        return $this->packages->getPackage('xxx')->getUrl('some-image.png');
    }
}

@deguif
Copy link
Contributor

deguif commented Mar 22, 2019

Nice, I already needed this in the past.
The main advantage for me would be that it triggers error during container compilation when package doesn't exist (instead of detecting it at runtime).

@gpenverne gpenverne force-pushed the improvement-alias-for-each-assets-package branch from 1d8767e to d89e46a Compare March 22, 2019 14:15
@gpenverne gpenverne force-pushed the improvement-alias-for-each-assets-package branch from d89e46a to e8b9856 Compare March 22, 2019 14:17
@nicolas-grekas nicolas-grekas added this to the next milestone Mar 25, 2019
@fabpot
Copy link
Member

fabpot commented Mar 25, 2019

@gpenverne Can you submit a PR on the docs?

@fabpot
Copy link
Member

fabpot commented Mar 27, 2019

Thank you @gpenverne.

@fabpot fabpot merged commit e8b9856 into symfony:master Mar 27, 2019
fabpot added a commit that referenced this pull request Mar 27, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

Alias for each assets package

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | ?     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | <!-- required for new features -->

Add autowiring by type + name on assets packages
```yaml
framework:
    assets:
        packages:
            xxx:
                base_urls: 'xxxx'
```
```php
<?php

class MyService
{
    private $xxxPackage;

    public function __construct(PackageInterface $xxxPackage)
    {
        $this->xxxPackage = $xxxPackage;
        ...
    }

    public function myMethod(): string
    {
        return $this->xxxPackage->getUrl('some-image.png');
    }
}
```
instead of:
```php
<?php

class MyService
{
    private $packages;

    public function __construct(Packages $packages)
    {
        $this->packages = $packages;
        ...
    }

    public function myMethod(): string
    {
        return $this->packages->getPackage('xxx')->getUrl('some-image.png');
    }
}
```

Commits
-------

e8b9856 Alias for each assets package
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants