-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Drastically improved debug:autowiring + new autowiring info system #26142
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
This introduces a new interface + tag that can be used by bundles to inform the core about the *purpose* of the autowirable classes/interfaces. This is makes debug:autowiring human-focused: showing you a list of the autowireable services based on the *purpose* of them.
6e10bf2
to
dffc922
Compare
@@ -15,6 +15,8 @@ | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
use Symfony\Component\Console\Style\SymfonyStyle; | |||
use Symfony\Component\DependencyInjection\Debug\AutowiringInfoManager; | |||
use Symfony\Component\DependencyInjection\Debug\AutowiringTypeInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this isn't used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are both used - one I think just for phpdoc :). We have a PR bot (fabbot) that validates cs, including unused use statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh how come include namespaces for just docblocks? Interesting!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It lets you use the short class names in phpdoc - like @param Foo - editors will use the use statement to know the full class name that you’re referencing :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool :)
*/ | ||
class AutowireDebugInfoPass implements CompilerPassInterface | ||
{ | ||
const AUTOWIRING_INFO_PROVIDER_TAG = 'debug.autowiring_info_provider'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public const
But needed? This is the first tag const right...
* | ||
* @return AutowiringTypeInfo|null | ||
*/ | ||
public function getInfo(string $type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: ?AutowiringTypeInfo
(docblock is redundant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I keep thinking Symfony requires 7.0, so no nullable types :). I'll change this happily
return isset($this->typeInfos[$type]) ? $this->typeInfos[$type] : null; | ||
} | ||
|
||
private function populateTypesInfo() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont do :void
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could for new APIs existing only in 4.1+
final class AutowiringTypeInfo | ||
{ | ||
private $type; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new lines to be removed
*/ | ||
public static function create(string $type, string $name, int $priority = 0) | ||
{ | ||
return new static($type, $name, $priority); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new self
will do as it's final
|
||
private $typeInfos = null; | ||
|
||
public function __construct(array $autowiringInfoProviders) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterable
to leverage type tagged
in DI
@@ -23,5 +23,13 @@ | |||
<argument type="service" id="debug.argument_resolver.inner" /> | |||
<argument type="service" id="debug.stopwatch" /> | |||
</service> | |||
|
|||
<service id="debug.autowiring_info_manager" class="Symfony\Component\DependencyInjection\Debug\AutowiringInfoManager"> | |||
<argument /> <!-- argument info providers --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type="tagged"
?
return; | ||
} | ||
|
||
$io->title('Key Services'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd say Main Services
/ Common Services
/ General Services
or so =/
AutowiringTypeInfo::create(Registry::class, 'Workflow') | ||
->setDescription('use to fetch workflows'), | ||
|
||
AutowiringTypeInfo::create(Registry::class, 'Workflow') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated :)
That's great!
|
For me the new priority will do (compared to suggested
Tend to like having all info at one place, compared to potentially scattered around all over. But doing it per service definition with definition config is reasonable (overkill IMHO). |
This is great. So nice that it shouldn't be limited to autowiring. It can be useful for other services, in other contexts (I think to the Graphviz dumper, and to the |
I’m going to rethink this in the context of all services, and possibly a new debug:services command that dumps things in a new way. Thanks for the suggestions :) |
Could we leverage PHPDocs of classes for this? As a fallback. Strip out tags, for example. But class (or interface) purpose probably matches service purpose. |
Closing in favor of #28970, thanks for pushing! |
Hey guys!
This PR makes debug:autowiring WAY more useful :). See screenshot at the bottom.
It's now human-focused: you look for the problem you need to solve (Cache, Logger, etc).
Note: if there are multiple types for the same thing - e.g.
Twig\Environment
&Twig_Environment
- then by convention, we'll choose one to "recommend" and onlyadd info about it. The other will still appear at the bottom of the list.
Behind the scenes, this introduces a new mini-system where bundles can tell the
core the purpose of the classes/interfaces that they expose. I didn't include
this at the container level (e.g. in Definition), because I think that's overkill:
this is just a nice decoration around the system. The system is also NOT included
when
kernel.debug = false
, so there's zero prod overhead. Thedebug:autowiring
command still works in this situation, but falls back to its original "one big list".
Cheers!