Skip to content

[DX] Remove default match from AbstractConfigCommand::findExtension #17456

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

Closed
wants to merge 1 commit into from

Conversation

kix
Copy link
Contributor

@kix kix commented Jan 20, 2016

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

Previously, findExtension would return the first extension that might not even match the $name parameter, which would quite confuse the user:

$ app/console config:debug TotallyNonExistentBundle
# Current configuration for "TotallyNonExistentBundle"
knp_paginator:
    default_options:
        sort_field_name: sort
        sort_direction_name: direction
        filter_field_name: filterField
        filter_value_name: filterValue
        page_name: page
        distinct: true
    template:
        pagination: 'KnpPaginatorBundle:Pagination:sliding.html.twig'
        filtration: 'KnpPaginatorBundle:Pagination:filtration.html.twig'
        sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig'
    page_range: 5

Same problem goes for the config:dump command. When you dumped the config for a bundle you thought you've registered, but, for example, you'd use a name that's not exactly matching, you'd get confusing output for a different bundle's configuration.

The problem was, an Extension was always fetched in the finder method, and name/alias misses were ignored.

@kix
Copy link
Contributor Author

kix commented Jan 20, 2016

The build failure seems unrelated to this PR: https://travis-ci.org/symfony/symfony/jobs/103599240#L3252

@wouterj
Copy link
Member

wouterj commented Jan 20, 2016

What about rewriting this like:

    $bundles = $this->initializeBundles();
    foreach ($bundles as $bundle) {
        if ($name === $bundle->getName()) {
            return $bundle->getContainerExtension();
        }

        $extension = $bundle->getContainerExtension();
        if ($extension && $name === $extension->getAlias()) {
            return $extension;
        }
    }

    if ('Bundle' !== substr($name -6)) {
        $message = sprintf('No extensions with configuration available for "%s"', $name);
    } else {
        $message = sprintf('No extension with alias "%s" is enabled', $name);
    }

    throw new \LogicException($message);
}

@kix
Copy link
Contributor Author

kix commented Jan 20, 2016

@wouterj, good idea, will update the PR. I just thought it could be better if less code was rewritten, but now I have to agree your code looks better :)

@kix kix force-pushed the fix-find-extension branch 4 times, most recently from 7fd1d07 to f797e12 Compare January 20, 2016 13:19
Previously, findExtension would return the first extension that might
not even match the $name parameter.
@kix kix force-pushed the fix-find-extension branch from f797e12 to ea1ded8 Compare January 20, 2016 13:20
@stof
Copy link
Member

stof commented Jan 20, 2016

👍

@wouterj
Copy link
Member

wouterj commented Jan 20, 2016

Status: reviewed

@fabpot
Copy link
Member

fabpot commented Jan 21, 2016

Thank you @kix.

fabpot added a commit that referenced this pull request Jan 21, 2016
…Extension (kix)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #17456).

Discussion
----------

[DX] Remove default match from AbstractConfigCommand::findExtension

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

Previously, `findExtension` would return the first extension that might not even match the `$name` parameter, which would quite confuse the user:

```
$ app/console config:debug TotallyNonExistentBundle
# Current configuration for "TotallyNonExistentBundle"
knp_paginator:
    default_options:
        sort_field_name: sort
        sort_direction_name: direction
        filter_field_name: filterField
        filter_value_name: filterValue
        page_name: page
        distinct: true
    template:
        pagination: 'KnpPaginatorBundle:Pagination:sliding.html.twig'
        filtration: 'KnpPaginatorBundle:Pagination:filtration.html.twig'
        sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig'
    page_range: 5
```

Same problem goes for the `config:dump` command. When you dumped the config for a bundle you thought you've registered, but, for example, you'd use a name that's not exactly matching, you'd get confusing output for a different bundle's configuration.

The problem was, an `Extension` [was always fetched in the finder method](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php#L51), and name/alias misses were ignored.

Commits
-------

b85059a Remove default match from AbstractConfigCommand::findExtension
@fabpot fabpot closed this Jan 21, 2016
@kix kix deleted the fix-find-extension branch January 21, 2016 08:30
@kix
Copy link
Contributor Author

kix commented Jan 21, 2016

Thanks for merging!

@fabpot fabpot mentioned this pull request Feb 3, 2016
This was referenced Feb 28, 2016
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