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

Alias for each assets package #30645

Merged

Conversation

Projects
None yet
5 participants
@gpenverne
Copy link
Contributor

commented Mar 22, 2019

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

This comment has been minimized.

Copy link
Contributor

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 gpenverne:improvement-alias-for-each-assets-package branch from 1d8767e to d89e46a Mar 22, 2019

@gpenverne gpenverne force-pushed the gpenverne:improvement-alias-for-each-assets-package branch from d89e46a to e8b9856 Mar 22, 2019

@nicolas-grekas nicolas-grekas added this to the next milestone Mar 25, 2019

@fabpot

This comment has been minimized.

Copy link
Member

commented Mar 25, 2019

@gpenverne Can you submit a PR on the docs?

@fabpot

fabpot approved these changes Mar 25, 2019

@fabpot

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

Thank you @gpenverne.

@fabpot fabpot merged commit e8b9856 into symfony:master Mar 27, 2019

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Mar 27, 2019

feature #30645 Alias for each assets package (gpenverne)
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 referenced this pull request May 9, 2019

Merged

Release v4.3.0-BETA1 #31435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.