Wire up route filters by tag in the container.

8.0.x
Larry Garfield 2012-12-26 15:30:39 -06:00
parent b0a1269f6c
commit 3319584a06
2 changed files with 12 additions and 22 deletions

View File

@ -10,7 +10,7 @@ namespace Drupal\Core;
use Drupal\Core\DependencyInjection\Compiler\RegisterKernelListenersPass; use Drupal\Core\DependencyInjection\Compiler\RegisterKernelListenersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass; use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterMatchersPass; use Drupal\Core\DependencyInjection\Compiler\RegisterMatchersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterNestedMatchersPass; use Drupal\Core\DependencyInjection\Compiler\RegisterRouteFiltersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterSerializationClassesPass; use Drupal\Core\DependencyInjection\Compiler\RegisterSerializationClassesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@ -195,21 +195,10 @@ class CoreBundle extends Bundle {
$container->register('password', 'Drupal\Core\Password\PhpassHashedPassword') $container->register('password', 'Drupal\Core\Password\PhpassHashedPassword')
->addArgument(16); ->addArgument(16);
// The following services are tagged as 'nested_matcher' services and are // The following services are tagged as 'route_filter' services and are
// processed in the RegisterNestedMatchersPass compiler pass. Each one // processed in the RegisterRouteFiltersPass compiler pass.
// needs to be set on the matcher using a different method, so we use a
// tag attribute, 'method', which can be retrieved and passed to the
// addMethodCall() method that gets called on the matcher service in the
// compiler pass.
$container->register('path_matcher', 'Drupal\Core\Routing\PathMatcher')
->addArgument(new Reference('database'))
->addTag('nested_matcher', array('method' => 'setInitialMatcher'));
$container->register('http_method_matcher', 'Drupal\Core\Routing\HttpMethodMatcher')
->addTag('nested_matcher', array('method' => 'addPartialMatcher'));
$container->register('mime_type_matcher', 'Drupal\Core\Routing\MimeTypeMatcher') $container->register('mime_type_matcher', 'Drupal\Core\Routing\MimeTypeMatcher')
->addTag('nested_matcher', array('method' => 'addPartialMatcher')); ->addTag('route_filter');
$container->register('first_entry_final_matcher', 'Drupal\Core\Routing\FirstEntryFinalMatcher')
->addTag('nested_matcher', array('method' => 'setFinalMatcher'));
$container->register('router_processor_subscriber', 'Drupal\Core\EventSubscriber\RouteProcessorSubscriber') $container->register('router_processor_subscriber', 'Drupal\Core\EventSubscriber\RouteProcessorSubscriber')
->addTag('event_subscriber'); ->addTag('event_subscriber');
@ -274,7 +263,9 @@ class CoreBundle extends Bundle {
->addArgument(new Reference('database')); ->addArgument(new Reference('database'));
$container->addCompilerPass(new RegisterMatchersPass()); $container->addCompilerPass(new RegisterMatchersPass());
$container->addCompilerPass(new RegisterNestedMatchersPass()); $container->addCompilerPass(new RegisterRouteFiltersPass());
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
// Add a compiler pass for adding Normalizers and Encoders to Serializer. // Add a compiler pass for adding Normalizers and Encoders to Serializer.
$container->addCompilerPass(new RegisterSerializationClassesPass()); $container->addCompilerPass(new RegisterSerializationClassesPass());
// Add a compiler pass for registering event subscribers. // Add a compiler pass for registering event subscribers.

View File

@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/** /**
* Adds services tagged 'nested_matcher' to the tagged_matcher service. * Adds services tagged 'nested_matcher' to the tagged_matcher service.
*/ */
class RegisterNestedMatchersPass implements CompilerPassInterface { class RegisterRouteFiltersPass implements CompilerPassInterface {
/** /**
* Adds services tagged 'nested_matcher' to the tagged_matcher service. * Adds services tagged 'nested_matcher' to the tagged_matcher service.
@ -23,13 +23,12 @@ class RegisterNestedMatchersPass implements CompilerPassInterface {
* The container to process. * The container to process.
*/ */
public function process(ContainerBuilder $container) { public function process(ContainerBuilder $container) {
if (!$container->hasDefinition('nested_matcher')) { if (!$container->hasDefinition('router.matcher')) {
return; return;
} }
$nested = $container->getDefinition('nested_matcher'); $nested = $container->getDefinition('router.matcher');
foreach ($container->findTaggedServiceIds('nested_matcher') as $id => $attributes) { foreach ($container->findTaggedServiceIds('router_filter') as $id => $attributes) {
$method = $attributes[0]['method']; $nested->addMethodCall('addRouteFilter', array(new Reference($id)));
$nested->addMethodCall($method, array(new Reference($id)));
} }
} }
} }