Skip to content

Added comments and fixes routing issue #48

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

Merged
merged 2 commits into from
Jan 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 55 additions & 40 deletions src/DependencyInjection/CacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
}
}
}
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/CacheTaggingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Tobias Nyholm <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/DoctrineCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* Class DoctrineSupportCompilerPass.
* Add the doctrine bridge around the PSR-6 cache services.
*
* @author Aaron Scherer <[email protected]>
* @author Tobias Nyholm <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/LoggingCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Class SessionSupportCompilerPass.
* Enable the session support by rewriting the "session.handler" alias.
*
* @author Aaron Scherer <[email protected]>
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/CachingRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand Down