Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Show injected services for iterator and array arguments #31353

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

Conversation

jschaedl
Copy link
Contributor

@jschaedl jschaedl commented May 1, 2019

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

When I have the following service configuration:

    App\Word\Checker\StaticWordChecker:
        tags: [app.checker]

    App\Word\Checker\BannedWorldListChecker:
        tags: [app.checker]

    App\Word\WordCheckerTaggedIterator:
        arguments: [!tagged app.checker]

    App\Word\WordCheckerArray:
        arguments:
            - App\Word\Checker\StaticWordChecker: ~
              App\Word\Checker\BannedWorldListChecker: ~

and I run:
./bin/console debug:container App\Word\WordCheckerArray --show-arguments

Information for Service "App\Word\WordCheckerArray"
===================================================

 ---------------- -------------------------------------------
  Option           Value
 ---------------- -------------------------------------------
  Service ID       App\Word\WordCheckerArray
  Class            App\Word\WordCheckerArray
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Array (2 element(s))
                   - App\Word\Checker\StaticWordChecker
                   - App\Word\Checker\BannedWorldListChecker
 ---------------- -------------------------------------------

or

./bin/console debug:container App\Word\WordCheckerTaggedIterator --show-arguments

Information for Service "App\Word\WordCheckerTaggedIterator"
============================================================

 ---------------- -------------------------------------------
  Option           Value
 ---------------- -------------------------------------------
  Service ID       App\Word\WordCheckerTaggedIterator
  Class            App\Word\WordCheckerTaggedIterator
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Iterator (2 element(s))
                   - App\Word\Checker\BannedWorldListChecker
                   - App\Word\Checker\StaticWordChecker
 ---------------- -------------------------------------------

I can now see the the objects injected into the iterator and array arguments.

@jschaedl jschaedl force-pushed the feature-31340_enhanced-information-debug-container-command branch from 2781480 to 21f7c9a Compare May 1, 2019 18:32
@linaori
Copy link
Contributor

linaori commented May 1, 2019

Should this be done on 3.4 instead? Currently 3.4 shows 0 instead of X in the iterator. This PR can be seen as a bug fix imo

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 1, 2019

We're too lax currently merging features as bug fixes, introducing regressions actually. Let's be a bit stricter, this is for master to me too.

@nicolas-grekas nicolas-grekas added this to the next milestone May 1, 2019
@linaori
Copy link
Contributor

linaori commented May 2, 2019

@nicolas-grekas for the value display, I can agree. The fact that this iterator is showing 0 instead of the actual amount is the initial bug I reported. Perhaps the PR could be split up to put the count fix in 3.4 and the list of services in the master?

@jschaedl
Copy link
Contributor Author

jschaedl commented May 2, 2019

@linaori The fact that this iterator is showing 0 in branch 3.4 is caused by the usage of a non compiled container in the ContainerDebugCommand (see: https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php#L184) as far as I can see it. Therefore the service definitions for the iterable arguments are not resolved and the TaggedIteratorArgument::getValues() is returning an empty array which leads to showing 0.

@nicolas-grekas Using a compiled container in the DebugContainerCommand was introduced in #27684 I think to fix this 0 issue, we need to do the same in the for 3.4.

@jschaedl jschaedl force-pushed the feature-31340_enhanced-information-debug-container-command branch from cc3c5d2 to db5fb20 Compare May 5, 2019 20:14
@fabpot
Copy link
Member

fabpot commented May 6, 2019

Thank you @jschaedl.

@fabpot fabpot merged commit db5fb20 into symfony:master May 6, 2019
fabpot added a commit that referenced this pull request May 6, 2019
…and array arguments (jschaedl)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[FrameworkBundle] Show injected services for iterator and array arguments

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      |no
| New feature?  | yes<!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- 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 | #31340   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | tbd.

When I have the following service configuration:

```yaml
    App\Word\Checker\StaticWordChecker:
        tags: [app.checker]

    App\Word\Checker\BannedWorldListChecker:
        tags: [app.checker]

    App\Word\WordCheckerTaggedIterator:
        arguments: [!tagged app.checker]

    App\Word\WordCheckerArray:
        arguments:
            - App\Word\Checker\StaticWordChecker: ~
              App\Word\Checker\BannedWorldListChecker: ~
```

and I run:
`./bin/console debug:container App\Word\WordCheckerArray --show-arguments`
```bash
Information for Service "App\Word\WordCheckerArray"
===================================================

 ---------------- -------------------------------------------
  Option           Value
 ---------------- -------------------------------------------
  Service ID       App\Word\WordCheckerArray
  Class            App\Word\WordCheckerArray
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Array (2 element(s))
                   - App\Word\Checker\StaticWordChecker
                   - App\Word\Checker\BannedWorldListChecker
 ---------------- -------------------------------------------
```
or

`./bin/console debug:container App\Word\WordCheckerTaggedIterator --show-arguments`
```bash
Information for Service "App\Word\WordCheckerTaggedIterator"
============================================================

 ---------------- -------------------------------------------
  Option           Value
 ---------------- -------------------------------------------
  Service ID       App\Word\WordCheckerTaggedIterator
  Class            App\Word\WordCheckerTaggedIterator
  Tags             -
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
  Arguments        Iterator (2 element(s))
                   - App\Word\Checker\BannedWorldListChecker
                   - App\Word\Checker\StaticWordChecker
 ---------------- -------------------------------------------
```

I can now see the the objects injected into the iterator and array arguments.

Commits
-------

db5fb20 [FrameworkBundle] Show injected services for Iterator and Array
@fabpot fabpot mentioned this pull request May 9, 2019
} elseif ($argument instanceof ServiceLocatorArgument) {
$argumentsInformation[] = sprintf('Service locator (%d element(s))', \count($argument->getValues()));
} elseif ($argument instanceof Definition) {
$argumentsInformation[] = 'Inlined Service';
} else {
$argumentsInformation[] = \is_array($argument) ? sprintf('Array (%d element(s))', \count($argument)) : $argument;
if (\is_array($argument)) {
foreach (array_keys($argument) as $service) {
$argumentsInformation[] = sprintf('- %s', $service);
Copy link
Member

@nicolas-grekas nicolas-grekas May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this part in 7a53e8d as I don't see how listing keys can be useful.

@@ -348,12 +348,20 @@ protected function describeContainerDefinition(Definition $definition, array $op
$argumentsInformation[] = sprintf('Service(%s)', (string) $argument);
} elseif ($argument instanceof IteratorArgument) {
$argumentsInformation[] = sprintf('Iterator (%d element(s))', \count($argument->getValues()));
foreach (array_map(function (Reference $value) {return (string) $value; }, $argument->getValues()) as $service) {
$argumentsInformation[] = sprintf('- %s', $service);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a reference, it should be displayed as Service(%s)
fixed in 7a53e8d too

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
@jschaedl jschaedl deleted the feature-31340_enhanced-information-debug-container-command branch February 23, 2020 08:01
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