Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Drastically improved debug:autowiring + new autowiring info system
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.
- Loading branch information
1 parent
7f8e215
commit 6e10bf2
Showing
17 changed files
with
556 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AutowireDebugInfoPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Looks for & processes debug.autowiring_info_provider tags. | ||
* | ||
* @author Ryan Weaver <ryan@knpuniversity.com> | ||
*/ | ||
class AutowireDebugInfoPass implements CompilerPassInterface | ||
{ | ||
const AUTOWIRING_INFO_PROVIDER_TAG = 'debug.autowiring_info_provider'; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if (false === $container->hasDefinition('debug.autowiring_info_manager')) { | ||
return; | ||
} | ||
|
||
$definition = $container->getDefinition('debug.autowiring_info_manager'); | ||
|
||
$references = array(); | ||
foreach ($container->findTaggedServiceIds(self::AUTOWIRING_INFO_PROVIDER_TAG, true) as $serviceId => $attributes) { | ||
$references[] = new Reference($serviceId); | ||
} | ||
|
||
$definition->replaceArgument(0, $references); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkAutowiringInfoProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; | ||
|
||
use Doctrine\Common\Annotations\Reader; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Psr\SimpleCache\CacheInterface; | ||
use Symfony\Component\Asset\Packages; | ||
use Symfony\Component\DependencyInjection\Debug\AutowiringInfoProviderInterface; | ||
use Symfony\Component\DependencyInjection\Debug\AutowiringTypeInfo; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use Symfony\Component\Stopwatch\Stopwatch; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
use Symfony\Component\Workflow\Registry; | ||
|
||
/** | ||
* @author Ryan Weaver <ryan@knpuniversity.com> | ||
*/ | ||
final class FrameworkAutowiringInfoProvider implements AutowiringInfoProviderInterface | ||
{ | ||
public function getTypeInfos(): array | ||
{ | ||
return array( | ||
AutowiringTypeInfo::create(CacheItemPoolInterface::class, 'Cache', 10) | ||
->setDescription('general-purpose service for caching things'), | ||
|
||
AutowiringTypeInfo::create(CacheInterface::class, 'Simple Cache', 10) | ||
->setDescription('simpler cache, but less features'), | ||
|
||
AutowiringTypeInfo::create(RouterInterface::class, 'Router', 10) | ||
->setDescription('used to generate URLs'), | ||
|
||
AutowiringTypeInfo::create(EventDispatcherInterface::class, 'Event Dispatcher') | ||
->setDescription('used to dispatch custom events'), | ||
|
||
AutowiringTypeInfo::create(Reader::class, 'Annotation Reader', -10), | ||
|
||
AutowiringTypeInfo::create(ParameterBagInterface::class, 'Parameter Bag') | ||
->setDescription('access service parameters'), | ||
|
||
AutowiringTypeInfo::create(Filesystem::class, 'Filesystem') | ||
->setDescription('helper for filesystem actions'), | ||
|
||
AutowiringTypeInfo::create(RequestStack::class, 'Request Stack') | ||
->setDescription('access the Request object'), | ||
|
||
AutowiringTypeInfo::create(SessionInterface::class, 'Session'), | ||
|
||
AutowiringTypeInfo::create(FlashBagInterface::class, 'Flash Bag') | ||
->setDescription('use to set temporary success/failure messages'), | ||
|
||
AutowiringTypeInfo::create(KernelInterface::class, 'Kernel'), | ||
|
||
AutowiringTypeInfo::create(Stopwatch::class, 'Stopwatch') | ||
->setDescription('use to add custom timings to profiler'), | ||
|
||
AutowiringTypeInfo::create(Packages::class, 'Asset Packages') | ||
->setDescription('use to generate URLs to assets'), | ||
|
||
AutowiringTypeInfo::create(FormFactoryInterface::class, 'Form Factory') | ||
->setDescription('use to create form objects'), | ||
|
||
AutowiringTypeInfo::create(ValidatorInterface::class, 'Validator') | ||
->setDescription('use to validate data against some constraints'), | ||
|
||
AutowiringTypeInfo::create(TranslatorInterface::class, 'Translator'), | ||
|
||
AutowiringTypeInfo::create(PropertyAccessorInterface::class, 'Property Accessor') | ||
->setDescription('use to read dynamic keys from some data'), | ||
|
||
AutowiringTypeInfo::create(CsrfTokenManagerInterface::class, 'CSRF Token Manager') | ||
->setDescription('generate and check CSRF tokens'), | ||
|
||
AutowiringTypeInfo::create(SerializerInterface::class, 'Serializer') | ||
->setDescription('use to serialize data to JSON, XML, etc'), | ||
|
||
AutowiringTypeInfo::create(Registry::class, 'Workflow') | ||
->setDescription('use to fetch workflows'), | ||
|
||
AutowiringTypeInfo::create(Registry::class, 'Workflow') | ||
->setDescription('use to fetch workflows'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityAutowiringInfoProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\Debug\AutowiringInfoProviderInterface; | ||
use Symfony\Component\DependencyInjection\Debug\AutowiringTypeInfo; | ||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; | ||
use Symfony\Component\Security\Core\Security; | ||
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; | ||
|
||
/** | ||
* @author Ryan Weaver <ryan@knpuniversity.com> | ||
*/ | ||
final class SecurityAutowiringInfoProvider implements AutowiringInfoProviderInterface | ||
{ | ||
public function getTypeInfos(): array | ||
{ | ||
return [ | ||
AutowiringTypeInfo::create(GuardAuthenticatorHandler::class, 'Guard Auth Handler') | ||
->setDescription('use to manually authenticate with Guard'), | ||
|
||
AutowiringTypeInfo::create(Security::class, 'Security') | ||
->setDescription('use to check access & get the current User'), | ||
|
||
AutowiringTypeInfo::create(UserPasswordEncoderInterface::class, 'Password Encoder') | ||
->setDescription('use to encode passwords & check them'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.