diff --git a/src/DependencyInjection/CacheExtension.php b/src/DependencyInjection/CacheExtension.php index 620ae07..cd3ae41 100644 --- a/src/DependencyInjection/CacheExtension.php +++ b/src/DependencyInjection/CacheExtension.php @@ -53,57 +53,21 @@ public function load(array $configs, ContainerBuilder $container) $this->verifyDoctrineBridgeExists('doctrine'); } - if ($config['annotation']['enabled']) { - $this->verifyDoctrineBridgeExists('annotation'); - $container->register('cache.service.annotation', DoctrineCacheBridge::class) - ->setFactory([DoctrineBridgeFactory::class, 'get']) - ->addArgument(new Reference($config['annotation']['service_id'])) - ->addArgument($config['annotation']) - ->addArgument('annotation'); - } - - if ($config['serializer']['enabled']) { - $this->verifyDoctrineBridgeExists('serializer'); - $container->register('cache.service.serializer', DoctrineCacheBridge::class) - ->setFactory([DoctrineBridgeFactory::class, 'get']) - ->addArgument(new Reference($config['serializer']['service_id'])) - ->addArgument($config['serializer']) - ->addArgument('serializer'); - } - - if ($config['validation']['enabled']) { - $container->register('cache.service.validation', SymfonyValidatorBridge::class) - ->setFactory([ValidationFactory::class, 'get']) - ->addArgument(new Reference($config['validation']['service_id'])) - ->addArgument($config['validation']); - } - - if ($config['session']['enabled']) { - $container->register('cache.service.session', Psr6SessionHandler::class) - ->setFactory([SessionHandlerFactory::class, 'get']) - ->addArgument(new Reference($config['session']['service_id'])) - ->addArgument($config['session']); - } - - if ($config['router']['enabled']) { - $container->register('cache.service.router', CachingRouter::class) - ->setDecoratedService('router', null, 10) - ->addArgument(new Reference($config['router']['service_id'])) - ->addArgument(new Reference('cache.service.router.inner')) - ->addArgument($config['router']); - } + $this->registerServices($container, $config); + // Add toolbar and data collector if we are debuging if ($container->getParameter('kernel.debug')) { $loader->load('data-collector.yml'); } + // Get a list of the psr-6 services we are using. $serviceIds = []; $this->findServiceIds($config, $serviceIds); $container->setParameter('cache.provider_service_ids', $serviceIds); } /** - * Find service ids that we configured. + * Find service ids that we configured. These services should be tagged so we can use them in the debug toolbar. * * @param array $config * @param array $serviceIds @@ -143,4 +107,55 @@ public function getAlias() { return 'cache'; } + + /** + * Register services. All service ids will start witn "cache.service.". + * + * @param ContainerBuilder $container + * @param $config + * + * @throws \Exception + */ + private function registerServices(ContainerBuilder $container, $config) + { + if ($config['annotation']['enabled']) { + $this->verifyDoctrineBridgeExists('annotation'); + $container->register('cache.service.annotation', DoctrineCacheBridge::class) + ->setFactory([DoctrineBridgeFactory::class, 'get']) + ->addArgument(new Reference($config['annotation']['service_id'])) + ->addArgument($config['annotation']) + ->addArgument('annotation'); + } + + if ($config['serializer']['enabled']) { + $this->verifyDoctrineBridgeExists('serializer'); + $container->register('cache.service.serializer', DoctrineCacheBridge::class) + ->setFactory([DoctrineBridgeFactory::class, 'get']) + ->addArgument(new Reference($config['serializer']['service_id'])) + ->addArgument($config['serializer']) + ->addArgument('serializer'); + } + + if ($config['validation']['enabled']) { + $container->register('cache.service.validation', SymfonyValidatorBridge::class) + ->setFactory([ValidationFactory::class, 'get']) + ->addArgument(new Reference($config['validation']['service_id'])) + ->addArgument($config['validation']); + } + + if ($config['session']['enabled']) { + $container->register('cache.service.session', Psr6SessionHandler::class) + ->setFactory([SessionHandlerFactory::class, 'get']) + ->addArgument(new Reference($config['session']['service_id'])) + ->addArgument($config['session']); + } + + if ($config['router']['enabled']) { + $container->register('cache.service.router', CachingRouter::class) + ->setDecoratedService('router', null, 10) + ->addArgument(new Reference($config['router']['service_id'])) + ->addArgument(new Reference('cache.service.router.inner')) + ->addArgument($config['router']); + } + } } diff --git a/src/DependencyInjection/Compiler/CacheTaggingPass.php b/src/DependencyInjection/Compiler/CacheTaggingPass.php index 47f64cb..3fa7949 100644 --- a/src/DependencyInjection/Compiler/CacheTaggingPass.php +++ b/src/DependencyInjection/Compiler/CacheTaggingPass.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * Make sure to tag all cache provider used. + * Make sure to tag all cache services we can find. * * @author Tobias Nyholm */ diff --git a/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php b/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php index 471bf7e..48920cc 100644 --- a/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php +++ b/src/DependencyInjection/Compiler/DataCollectorCompilerPass.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Class DataCollectorCompilerPass. + * Inject a data collector to all the cache services to be able to get detailed statistics. * * @author Aaron Scherer * @author Tobias Nyholm diff --git a/src/DependencyInjection/Compiler/DoctrineCompilerPass.php b/src/DependencyInjection/Compiler/DoctrineCompilerPass.php index 6a094d0..0e2ac7f 100644 --- a/src/DependencyInjection/Compiler/DoctrineCompilerPass.php +++ b/src/DependencyInjection/Compiler/DoctrineCompilerPass.php @@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Class DoctrineSupportCompilerPass. + * Add the doctrine bridge around the PSR-6 cache services. * * @author Aaron Scherer * @author Tobias Nyholm diff --git a/src/DependencyInjection/Compiler/LoggingCompilerPass.php b/src/DependencyInjection/Compiler/LoggingCompilerPass.php index bb9c033..6c3ef06 100644 --- a/src/DependencyInjection/Compiler/LoggingCompilerPass.php +++ b/src/DependencyInjection/Compiler/LoggingCompilerPass.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Decorate our cache.provider with a logger. + * Decorate our cache.providers with a logger. * * @author Tobias Nyholm */ diff --git a/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php b/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php index a86aa79..fc2b3bc 100644 --- a/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php +++ b/src/DependencyInjection/Compiler/SessionSupportCompilerPass.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * Class SessionSupportCompilerPass. + * Enable the session support by rewriting the "session.handler" alias. * * @author Aaron Scherer */ diff --git a/src/Routing/CachingRouter.php b/src/Routing/CachingRouter.php index 0288bea..33897d1 100644 --- a/src/Routing/CachingRouter.php +++ b/src/Routing/CachingRouter.php @@ -125,7 +125,7 @@ private function getCacheItemMatch($pathinfo) { /** @type RequestContext $c */ $c = $this->getContext(); - $key = sprintf('%s__%s__%s__%s', $c->getMethod(), $c->getHost(), $pathinfo, $c->getQueryString()); + $key = sprintf('%s__%s__%s__%s', $c->getHost(), str_replace('/', '.', $pathinfo), $c->getMethod(), $c->getQueryString()); return $this->getCacheItemFromKey($key, 'match'); } @@ -141,8 +141,8 @@ private function getCacheItemMatch($pathinfo) */ private function getCacheItemGenerate($name, array $parameters, $referenceType) { - sort($parameters); - $key = sprintf('%s.%s.%s', $name, $referenceType ? 'true' : 'false', json_encode($parameters)); + asort($parameters); + $key = sprintf('%s.%s.%s', $name, $referenceType ? 'true' : 'false', http_build_query($parameters)); return $this->getCacheItemFromKey($key, 'generate'); }