Skip to content

[Command] Improve --show-arguments for command debug:container #58718

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

chadyred
Copy link
Contributor

@chadyred chadyred commented Oct 30, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

Hello,

I improved the text descriptor and test for of the "--show-arguments" command in order to show in a service locator (arguments or a tagged iterator) and other iterator argument to display more information of the services in the arguments.

I moved information of arguments just after the main table because a lots of service could exist.

A fake class for a test :

<?php

declare(strict_types=1);

namespace App\Service\Fake;

use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;

readonly class ServiceWithTaggedIteratorAndServiceLocatorInjection
{
    public function __construct(
        public array           $simpleIterator,
        public \Closure           $serviceLocatorAsClosure,
        #[AutowireLocator(services: [
            'one' => One::class,
            'two' => Two::class,
        ])]
        public ContainerInterface $autowireLocator,
        #[AutowireLocator('app.fake_tag')]
        public ContainerInterface $autowireLocatorWithStringTag,
        #[AutowireIterator('app.fake_tag')]
        public ContainerInterface $taggedLocator,
        public ContainerInterface $servicesTagged,
        public ServiceHasLocator  $serviceLocator,
        public ContainerInterface $containerServiceLocator,
        public ContainerInterface $containerServiceLocatorNotAutoconfigure,
        public string $abstractArg,
        public FooEnum $enumArg,
        public array $iteratorArgument,
    )
    {
    }
}

Its yaml services configuration :

services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'

    App\Service\Fake\One:
        tags: [{name: 'app.fake_tag'}, {name: 'app.fake_tag_2'}]

    App\Service\Fake\Two:
        tags: [{name: 'app.fake_tag'}, {name: 'app.fake_tag_2'}]

    App\Service\Fake\Three:
        tags: [{name: 'app.fake_tag'}, {name: 'app.fake_tag_2'}]

    App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection:
        arguments:
            $containerServiceLocator: '@my.locator'
            $simpleIterator: ['@App\Service\Fake\One', '@App\Service\Fake\Two']
            $serviceLocatorAsClosure: !service_locator
              App\Service\Fake\One: '@App\Service\Fake\One'
              App\Service\Fake\Two: '@App\Service\Fake\Two'
            $taggedLocator: !tagged_locator {tag: 'app.fake_tag_2'}
            $servicesTagged: !tagged_iterator {tag: 'app.fake_tag'}
            $serviceLocator: '@App\Service\Fake\ServiceHasLocator' # Not expanded, it is a service which has a locator in its own context
            $containerServiceLocatorNotAutoconfigure: '@my.locator_not_autoconfigure'
            $abstractArg: !abstract 'should be defined by Pass'
            $enumArg: !php/enum App\Service\Fake\FooEnum::ONE
            $iteratorArgument:
              - '@App\Service\Fake\One'
              - '@App\Service\Fake\Two'

    my.locator: # A classical locator
      class: Symfony\Component\DependencyInjection\ServiceLocator
      arguments:
        - router: '@router'
          request_stack: '@request_stack'
          http_kernel: '@http_kernel'
          session: '@session'
          parameter_bag: '@parameter_bag'
          contact_email: "mail@contact.com"
          mailerAsClosure: !service_closure '@mailer'

    my.locator_not_autoconfigure:
      autoconfigure: false
      class: Symfony\Component\DependencyInjection\ServiceLocator
      arguments:
        - router: '@router'
          request_stack: '@request_stack'
          http_kernel: '@http_kernel'
          session: '@session'
          parameter_bag: '@parameter_bag'
      tags: [ 'container.service_locator' ]

Before :

php bin/console deb:cont "ServiceWithTaggedIteratorAndServiceLocatorInjection" --show-arguments

Information for Service "App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection"
==============================================================================================

 ---------------- ---------------------------------------------------------------------- 
  Option           Value                                                                 
 ---------------- ---------------------------------------------------------------------- 
  Service ID       App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection  
  Class            App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection  
  Tags             -                                                                     
  Public           no                                                                    
  Synthetic        no                                                                    
  Lazy             no                                                                    
  Shared           yes                                                                   
  Abstract         no                                                                    
  Autowired        yes                                                                   
  Autoconfigured   yes                                                                   
  Arguments        Array (2 element(s))                                                  
                   Service(.service_locator.BU3KPRp)                                     
                   Service(.service_locator.oF5goiR)                                     
                   Service(.service_locator.AdwCYyt)                                     
                   Service(.service_locator.idLRJzM)                                     
                   Tagged Iterator for "app.fake_tag"                                    
                   Service(App\Service\Fake\ServiceHasLocator)                           
                   Service(my.locator)                                                   
                   Service(my.locator_not_autoconfigure)                                 
                   Abstract argument (should be defined by Pass)                         
                   App\Service\Fake\FooEnum::ONE                                         
                   Array (2 element(s))                                                  
  Usages           none                                                                  
 ---------------- ---------------------------------------------------------------------- 

After :

php bin/console deb:cont "ServiceWithTaggedIteratorAndServiceLocatorInjection" --show-arguments

Information for Service "App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection"
==============================================================================================

 ---------------- ---------------------------------------------------------------------- 
  Option           Value                                                                 
 ---------------- ---------------------------------------------------------------------- 
  Service ID       App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection  
  Class            App\Service\Fake\ServiceWithTaggedIteratorAndServiceLocatorInjection  
  Tags             -                                                                     
  Public           no                                                                    
  Synthetic        no                                                                    
  Lazy             no                                                                    
  Shared           yes                                                                   
  Abstract         no                                                                    
  Autowired        yes                                                                   
  Autoconfigured   yes                                                                   
  Usages           none                                                                  
 ---------------- ---------------------------------------------------------------------- 

+----+---------------------------- Arguments --------+------------------------+
| #  | Service                                       | Argument(s)            |
+----+-----------------------------------------------+------------------------+
| 1  | Service locator (7 element(s))                | router.default         |
|    |                                               | request_stack          |
|    |                                               | http_kernel            |
|    |                                               | session                |
|    |                                               | parameter_bag          |
|    |                                               | ["mail@contact.com"]   |
|    |                                               | mailer.mailer          |
+----+-----------------------------------------------+------------------------+
| 2  | Array (2 element(s))                          | -                      |
+----+-----------------------------------------------+------------------------+
| 3  | Service locator (2 element(s))                | App\Service\Fake\One   |
|    |                                               | App\Service\Fake\Two   |
+----+-----------------------------------------------+------------------------+
| 4  | Service locator (2 element(s))                | App\Service\Fake\One   |
|    |                                               | App\Service\Fake\Two   |
+----+-----------------------------------------------+------------------------+
| 5  | Service locator (3 element(s))                | App\Service\Fake\Three |
|    |                                               | App\Service\Fake\Two   |
|    |                                               | App\Service\Fake\One   |
+----+-----------------------------------------------+------------------------+
| 6  | Service locator (3 element(s))                | App\Service\Fake\Two   |
|    |                                               | App\Service\Fake\Three |
|    |                                               | App\Service\Fake\One   |
+----+-----------------------------------------------+------------------------+
| 7  | Tagged Iterator for "app.fake_tag"            | App\Service\Fake\One   |
|    |                                               | App\Service\Fake\Three |
|    |                                               | App\Service\Fake\Two   |
+----+-----------------------------------------------+------------------------+
| 8  | Service(App\Service\Fake\ServiceHasLocator)   | -                      |
+----+-----------------------------------------------+------------------------+
| 9  | Service locator (5 element(s))                | router.default         |
|    |                                               | request_stack          |
|    |                                               | http_kernel            |
|    |                                               | session                |
|    |                                               | parameter_bag          |
+----+-----------------------------------------------+------------------------+
| 10 | Abstract argument (should be defined by Pass) | -                      |
+----+-----------------------------------------------+------------------------+
| 11 | App\Service\Fake\FooEnum::ONE                 | -                      |
+----+-----------------------------------------------+------------------------+
| 12 | Array (2 element(s))                          | -                      |
+----+-----------------------------------------------+------------------------+
                            

I try to cover any sort of argument with the use of a locator into a service, but it could be useful to me if you have more cases to test (maybe some type, some kind of Definition or anything could be useful).

Thanks a lot :)

@carsonbot carsonbot added this to the 7.2 milestone Oct 30, 2024
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch from 969c6e8 to 69c922b Compare October 30, 2024 15:20
@chadyred chadyred changed the title [WIP][Command] Improve --show-arguments for command debug:container [Command] Improve --show-arguments for command debug:container Oct 30, 2024
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch 3 times, most recently from ffbbac9 to eb0dd52 Compare October 30, 2024 16:42
@chadyred
Copy link
Contributor Author

chadyred commented Nov 1, 2024

Status: Needs Review

@chadyred
Copy link
Contributor Author

chadyred commented Nov 6, 2024

Hello,

We pick only the fact to show or not the arguments, and it is explicit, -v is great to do "expand infos", for command with interaction, but we could add options to choose what we really need to show, and we could add many and many options, and the -v imply that we have to show all the content of all options ?

Symfony uses option as unit when we need a piece of information.. It is possible to combine both : --show-arguments with -vvv, but to me, it is not enough clear...You choose to show or not something, -v and various -vv, -vvv could imply many level of information etc

@chadyred
Copy link
Contributor Author

chadyred commented Nov 6, 2024

You ask about the "array", I look at them : an ArrayArgument could contain : scalar, object etc so I stop by keeping previous code which indicate the "count" of the array. We have to check each type, find the good way to display informatino about them...and display it without beaking things (json_encode ?) but if it is a big object, or array etc...we have to truncate. So, I think about doing that into another PR.

@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch 2 times, most recently from 93d9fc4 to 48ffd47 Compare November 18, 2024 09:36
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch 3 times, most recently from 5376468 to 2289fd1 Compare November 26, 2024 09:48
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch 2 times, most recently from 0fa4aac to ceac852 Compare December 9, 2024 09:08
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch from ceac852 to 2a55d6c Compare December 13, 2024 12:46
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch from 2a55d6c to 118cf3a Compare December 16, 2024 09:33
@chadyred chadyred force-pushed the feat/list-locator-services-command-debug branch 2 times, most recently from a9d019a to 118cf3a Compare January 8, 2025 15:35
@chadyred
Copy link
Contributor Author

chadyred commented Jan 8, 2025

Close because --show-arguments is mark as deprecated

@chadyred chadyred closed this Jan 8, 2025
@chalasr
Copy link
Member

chalasr commented Jan 8, 2025

The option is deprecated because arguments will always be shown as of Symfony 7.3. So improving the arguments representation is welcome (note that I didn't review this yet though)

@chadyred
Copy link
Contributor Author

chadyred commented Jan 8, 2025

Thanks @chalasr, I reopen, I have to take time to rework the pull request. But now, the arguments are always visible,, my table seems ugly and not acceptable for DX IMO.

  1. I think about something with the -v
  2. Or why not with a future tree helper something like
1. Service Locator (7 éléments)
├── router.default
├── request_stack
├── http_kernel
├── session
├── parameter_bag
├── ["mail@contact.com"]
└── mailer.mailer

2. Array (2 éléments)
└── -

3. Service Locator (2 éléments)
├── App\Service\Fake\One
└── App\Service\Fake\Two

4. Service Locator (2 éléments)
├── App\Service\Fake\One
└── App\Service\Fake\Two

5. Service Locator (3 éléments)
├── App\Service\Fake\Three
├── App\Service\Fake\Two
└── App\Service\Fake\One

6. Service Locator (3 éléments)
├── App\Service\Fake\Two
├── App\Service\Fake\Three
└── App\Service\Fake\One

7. Tagged Iterator pour "app.fake_tag"
├── App\Service\Fake\One
├── App\Service\Fake\Three
└── App\Service\Fake\Two

8. Service (App\Service\Fake\ServiceHasLocator)
└── -

9. Service Locator (5 éléments)
├── router.default
├── request_stack
├── http_kernel
├── session
└── parameter_bag

10. Abstract Argument (devrait être défini par Pass)
└── -

11. App\Service\Fake\FooEnum::ONE
└── -

12. Array (2 éléments)
└── -

OR

+--------------------+
| Type: object       |
| Class: MyClassA    |
| Object Handle: 4   |
| Children count: 1  |
+--------------------+
         ^
         |
         3
         |
         |
+---------------------+
| Type: array         |
| Is root: No         |
| Children count: 100 |
+---------------------+
         ^
         |
    second level
         |
         |
+--------------------+
| Type: array        |
| Is root: No        |
| Children count: 1  |
+--------------------+
         ^
         |
    first level
         |
         |
+---------------------------+
| Type: array               |
| Is root: Yes              |
| Children count: 1         |
+---------------------------+

@chadyred chadyred reopened this Jan 8, 2025
@chadyred
Copy link
Contributor Author

chadyred commented Jan 8, 2025

Status: Needs work

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.

4 participants