Skip to content

[WIP][FrameworkBundle] Add debug autoconfigure command #28730

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

Conversation

aaa2000
Copy link
Contributor

@aaa2000 aaa2000 commented Oct 4, 2018

Close #26295

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #26295
License MIT
Doc PR symfony/symfony-docs#...

Replace the pull request #26745.

Creation of a new command as proposed in the comment #26745 (comment) to show the full template of the autoconfigure of interfaces/classes

Output of the command based on modified symfony-demo application to have binding autoconfiguration, multiple tags attributes and multiple method calls

sf debug:autoconfiguration 

Autoconfiguration
=================


Autoconfiguration for "App\Twig\AppExtension"
==============================================

 ---------- -------------------- 
  Option     Value               
 ---------- -------------------- 
  Tag        app.twig.extension  
  Bindings   $locales: fr|en|es  
                                 
 ---------- -------------------- 

Autoconfiguration for "Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface"
==============================================

 -------- ----------------------------- 
  Option   Value                        
 -------- ----------------------------- 
  Tag      doctrine.repository_service  
 -------- ----------------------------- 

Autoconfiguration for "Doctrine\Bundle\FixturesBundle\ORMFixtureInterface"
==============================================

 -------- ---------------------- 
  Option   Value                 
 -------- ---------------------- 
  Tag      doctrine.fixture.orm  
 -------- ---------------------- 

Autoconfiguration for "Psr\Log\LoggerAwareInterface"
==============================================

 ------------- ---------------------------- 
  Option        Value                       
 ------------- ---------------------------- 
  Method call   - [setLogger, ['@logger']]  
                - [setLogger, ['@logger']]  
                                            
 ------------- ---------------------------- 

Autoconfiguration for "Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface"
==============================================

 -------- ------------------------- 
  Option   Value                    
 -------- ------------------------- 
  Tag      request.param_converter  
 -------- ------------------------- 

Autoconfiguration for "Symfony\Bridge\Monolog\Processor\ProcessorInterface"
==============================================

 -------- ------------------- 
  Option   Value              
 -------- ------------------- 
  Tag      monolog.processor  
 -------- ------------------- 

Autoconfiguration for "Symfony\Bundle\FrameworkBundle\Controller\AbstractController"
==============================================

 -------- ------------------------------ 
  Option   Value                         
 -------- ------------------------------ 
  Tag      controller.service_arguments  
 -------- ------------------------------ 

Autoconfiguration for "Symfony\Bundle\FrameworkBundle\Controller\Controller"
==============================================

 -------- ------------------------------ 
  Option   Value                         
 -------- ------------------------------ 
  Tag      controller.service_arguments  
 -------- ------------------------------ 

Autoconfiguration for "Symfony\Component\Config\ResourceCheckerInterface"
==============================================

 -------- ------------------------------- 
  Option   Value                          
 -------- ------------------------------- 
  Tag      config_cache.resource_checker  
 -------- ------------------------------- 

Autoconfiguration for "Symfony\Component\Console\Command\Command"
==============================================

 -------- ----------------- 
  Option   Value            
 -------- ----------------- 
  Tag      console.command  
 -------- ----------------- 

Autoconfiguration for "Symfony\Component\DependencyInjection\EnvVarProcessorInterface"
==============================================

 -------- ----------------------------- 
  Option   Value                        
 -------- ----------------------------- 
  Tag      container.env_var_processor  
 -------- ----------------------------- 

Autoconfiguration for "Symfony\Component\DependencyInjection\ServiceLocator"
==============================================

 -------- --------------------------- 
  Option   Value                      
 -------- --------------------------- 
  Tag      container.service_locator  
 -------- --------------------------- 

Autoconfiguration for "Symfony\Component\EventDispatcher\EventSubscriberInterface"
==============================================

 -------- ------------------------- 
  Option   Value                    
 -------- ------------------------- 
  Tag      kernel.event_subscriber  
 -------- ------------------------- 

Autoconfiguration for "Symfony\Component\Form\FormTypeGuesserInterface"
==============================================

 -------- ------------------- 
  Option   Value              
 -------- ------------------- 
  Tag      form.type_guesser  
 -------- ------------------- 

Autoconfiguration for "Symfony\Component\Form\FormTypeInterface"
==============================================

 -------- ----------- 
  Option   Value      
 -------- ----------- 
  Tag      form.type  
 -------- ----------- 

Autoconfiguration for "Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface"
==============================================

 -------- ---------------------- 
  Option   Value                 
 -------- ---------------------- 
  Tag      kernel.cache_clearer  
 -------- ---------------------- 

Autoconfiguration for "Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface"
==============================================

 -------- --------------------- 
  Option   Value                
 -------- --------------------- 
  Tag      kernel.cache_warmer  
 -------- --------------------- 

Autoconfiguration for "Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface"
==============================================

 -------- ------------------------------------ 
  Option   Value                               
 -------- ------------------------------------ 
  Tag      controller.argument_value_resolver  
 -------- ------------------------------------ 

Autoconfiguration for "Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface"
==============================================

 -------- ---------------- 
  Option   Value           
 -------- ---------------- 
  Tag      data_collector  
 -------- ---------------- 

Autoconfiguration for "Symfony\Component\Messenger\Handler\MessageHandlerInterface"
==============================================

 -------- --------------------------- 
  Option   Value                      
 -------- --------------------------- 
  Tag      messenger.message_handler  
 -------- --------------------------- 

Autoconfiguration for "Symfony\Component\Messenger\Transport\TransportFactoryInterface"
==============================================

 -------- ----------------------------- 
  Option   Value                        
 -------- ----------------------------- 
  Tag      messenger.transport_factory  
 -------- ----------------------------- 

Autoconfiguration for "Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface"
==============================================

 -------- -------------------------------- 
  Option   Value                           
 -------- -------------------------------- 
  Tag      property_info.access_extractor  
 -------- -------------------------------- 

Autoconfiguration for "Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface"
==============================================

 -------- ------------------------------------- 
  Option   Value                                
 -------- ------------------------------------- 
  Tag      property_info.description_extractor  
 -------- ------------------------------------- 

Autoconfiguration for "Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface"
==============================================

 -------- --------------------------------------- 
  Option   Value                                  
 -------- --------------------------------------- 
  Tag      property_info.initializable_extractor  
 -------- --------------------------------------- 

Autoconfiguration for "Symfony\Component\PropertyInfo\PropertyListExtractorInterface"
==============================================

 -------- ------------------------------ 
  Option   Value                         
 -------- ------------------------------ 
  Tag      property_info.list_extractor  
 -------- ------------------------------ 

Autoconfiguration for "Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface"
==============================================

 -------- ------------------------------ 
  Option   Value                         
 -------- ------------------------------ 
  Tag      property_info.type_extractor  
 -------- ------------------------------ 

Autoconfiguration for "Symfony\Component\Security\Core\Authorization\Voter\VoterInterface"
==============================================

 -------- ---------------- 
  Option   Value           
 -------- ---------------- 
  Tag      security.voter  
 -------- ---------------- 

Autoconfiguration for "Symfony\Component\Serializer\Encoder\DecoderInterface"
==============================================

 -------- -------------------- 
  Option   Value               
 -------- -------------------- 
  Tag      serializer.encoder  
 -------- -------------------- 

Autoconfiguration for "Symfony\Component\Serializer\Encoder\EncoderInterface"
==============================================

 -------- -------------------- 
  Option   Value               
 -------- -------------------- 
  Tag      serializer.encoder  
 -------- -------------------- 

Autoconfiguration for "Symfony\Component\Serializer\Normalizer\DenormalizerInterface"
==============================================

 -------- ----------------------- 
  Option   Value                  
 -------- ----------------------- 
  Tag      serializer.normalizer  
 -------- ----------------------- 

Autoconfiguration for "Symfony\Component\Serializer\Normalizer\NormalizerInterface"
==============================================

 -------- ----------------------- 
  Option   Value                  
 -------- ----------------------- 
  Tag      serializer.normalizer  
 -------- ----------------------- 

Autoconfiguration for "Symfony\Component\Validator\ConstraintValidatorInterface"
==============================================

 -------- -------------------------------- 
  Option   Value                           
 -------- -------------------------------- 
  Tag      validator.constraint_validator  
 -------- -------------------------------- 

Autoconfiguration for "Symfony\Component\Validator\ObjectInitializerInterface"
==============================================

 -------- ----------------------- 
  Option   Value                  
 -------- ----------------------- 
  Tag      validator.initializer  
 -------- ----------------------- 

Autoconfiguration for "Symfony\Contracts\Service\ResetInterface"
==============================================

 --------------- -------------------------- 
  Option          Value                     
 --------------- -------------------------- 
  Tag             kernel.reset              
  Tag attribute   [                         
                    [                       
                      "method" => "reset"   
                    ]                       
                  ]                         
                                            
  Tag             kernel.reset2             
  Tag attribute   [                         
                    [                       
                      "method" => "reset2"  
                    ]                       
                  ]                         
                                            
 --------------- -------------------------- 

Autoconfiguration for "Symfony\Contracts\Service\ServiceSubscriberInterface"
==============================================

 -------- ------------------------------ 
  Option   Value                         
 -------- ------------------------------ 
  Tag      container.service_subscriber  
 -------- ------------------------------ 

Autoconfiguration for "Twig\Extension\ExtensionInterface"
==============================================

 -------- ---------------- 
  Option   Value           
 -------- ---------------- 
  Tag      twig.extension  
 -------- ---------------- 

Autoconfiguration for "Twig\Extension\RuntimeExtensionInterface"
==============================================

 -------- -------------- 
  Option   Value         
 -------- -------------- 
  Tag      twig.runtime  
 -------- -------------- 

Autoconfiguration for "Twig\Loader\LoaderInterface"
==============================================

 -------- ------------- 
  Option   Value        
 -------- ------------- 
  Tag      twig.loader  
 -------- ------------- 

Autoconfiguration for "Twig_ExtensionInterface"
==============================================

 -------- ---------------- 
  Option   Value           
 -------- ---------------- 
  Tag      twig.extension  
 -------- ---------------- 

Autoconfiguration for "Twig_LoaderInterface"
==============================================

 -------- ------------- 
  Option   Value        
 -------- ------------- 
  Tag      twig.loader  
 -------- ------------- 

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, here is a round of comments.

}
$tableRows[] = array('Public', $autoconfiguredInstanceofItem->isPublic() ? 'yes' : 'no');
$tableRows[] = array('Shared', $autoconfiguredInstanceofItem->isShared() ? 'yes' : 'no');
$tableRows[] = array('Autowired', $autoconfiguredInstanceofItem->isAutowired() ? 'yes' : 'no');
Copy link
Member

Choose a reason for hiding this comment

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

The only things that can be set by autoconfiguration are tags, method calls and bindings.
There is no need to list anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed Public, Shared and Autowired and I add bindings

}

if ($tags && array_values($tags) !== array(array(array()))) {
$tableRows[] = array('Tags attributes', $this->dumpTagsAttributes($tags));
Copy link
Member

Choose a reason for hiding this comment

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

If there are any attributes, they should be listed next to their corresponding tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are many attributes, the command displays like that

 --------------- -------------------------- 
  Option          Value                     
 --------------- -------------------------- 
  Tag             kernel.reset              
  Tag attribute   [                         
                    [                       
                      "method" => "reset"   
                    ]                       
                  ]                         
                                            
  Tag             kernel.reset2             
  Tag attribute   [                         
                    [                       
                      "method" => "reset2"  
                    ]                       
                  ]                         
                                            
 --------------- -------------------------- 

@nicolas-grekas nicolas-grekas added this to the next milestone Oct 5, 2018
/** @var ChildDefinition $autoconfiguredInstanceofItem */
foreach ($autoconfiguredInstanceofItems as $key => $autoconfiguredInstanceofItem) {
$tags = $autoconfiguredInstanceofItem->getTags();
$tableRows = array();
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can get rid of the $tableRows array by using addRow() and render(), as this is for master. IMO its more readable afterwards

docs: https://symfony.com/doc/current/components/console/helpers/table.html#modifying-rendered-tables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure it's more readable. To have the same style that the others commands, it is necessary to configure the table.

diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutoconfigurationCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutoconfigurationCommand.php
index bffdd32751..6d80649634 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutoconfigurationCommand.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutoconfigurationCommand.php
@@ -12,6 +12,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Command;
 
 use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\Table;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
Stash this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -91,26 +92,30 @@ EOF
 
         /** @var ChildDefinition $autoconfiguredInstanceofItem */
         foreach ($autoconfiguredInstanceofItems as $key => $autoconfiguredInstanceofItem) {
-            $tableRows = array();
+            $section = $output->section();
+            $table = new Table($section);
+            $table->setStyle(Table::getStyleDefinition('symfony-style-guide'));
+            $table->addRow(array('Option', 'Value'));
 
             foreach ($autoconfiguredInstanceofItem->getTags() as $tag => $tagAttributes) {
-                $tableRows[] = array('Tag', $tag);
+                $table->addRow(array('Tag', $tag));
                 if ($tagAttributes !== array(array())) {
-                    $tableRows[] = array('Tag attribute', $this->dumpTagAttribute($tagAttributes));
+                    $table->addRow(array('Tag attribute', $this->dumpTagAttribute($tagAttributes)));
                 }
             }
 
             if ($autoconfiguredInstanceofItem->getMethodCalls()) {
-                $tableRows[] = array('Method call', $this->dumpMethodCall($autoconfiguredInstanceofItem));
+                $table->addRow(array('Method call', $this->dumpMethodCall($autoconfiguredInstanceofItem)));
             }
 
             if ($autoconfiguredInstanceofItem->getBindings()) {
-                $tableRows[] = array('Bindings', $this->dumpBindings($autoconfiguredInstanceofItem));
+                $table->addRow(array('Bindings', $this->dumpBindings($autoconfiguredInstanceofItem)));
             }
 
             $io->writeln(sprintf("Autoconfiguration for \"%s\"\n==============================================", $key));
             $io->newLine();
-            $io->table(array('Option', 'Value'), $tableRows);
+            $table->render();
+            $io->newLine();
         }
     }

@OskarStark
Copy link
Contributor

OskarStark commented Oct 6, 2018

Could you please post a screenshot of the output?

EDIT: Please add it to the PR header

@aaa2000 aaa2000 force-pushed the debug-autoconfiguration-command branch from 35a8f47 to 09ea820 Compare October 9, 2018 21:02
@aaa2000 aaa2000 changed the title [FrameworkBundle] Add debug autoconfigure command [WIP][FrameworkBundle] Add debug autoconfigure command Oct 9, 2018
@aaa2000
Copy link
Contributor Author

aaa2000 commented Oct 9, 2018

@OskarStark Have you seen the output of command in the PR header, it requires to unfold. Do you prefer a screenshot ?

@@ -0,0 +1,9 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\DebugAutoconfigurationBundle;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, I can use the TestBundle instead of create a new bundle ?

Fix many setMethodCalls display
Fix autoconfiguration display
Add bindings display
Add tests with class fixtures
@aaa2000 aaa2000 force-pushed the debug-autoconfiguration-command branch from 4074a0d to 00fb8ae Compare October 13, 2018 09:48
@OskarStark
Copy link
Contributor

Ah i missed it 😊

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

not sure we need a new command, feels like it should be part of debug:container --autoconfiguration instead. Re-building and YAML dumping the container here looks suspicious to me.

Alternatively extend from ContainerDebugCommand like DebugAutowiringCommand also does.

@aaa2000
Copy link
Contributor Author

aaa2000 commented Nov 1, 2018

Re-building and YAML dumping the container here looks suspicious to me.

Ok, I don't like it too but I didn't see other way to display method calls and bindings.

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.

[RFC] [DI][Debug] Add command to debug autoconfigure tags
5 participants