Created specific factory for AppOptions to prevent circular dependency with cache

This commit is contained in:
Alejandro Celaya
2016-08-15 23:40:49 +02:00
parent ffa6c0d2ca
commit 5ca4bc928d
6 changed files with 77 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ namespace Shlinkio\Shlink\Common\Factory;
use Doctrine\Common\Cache;
use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Shlinkio\Shlink\Core\Options\AppOptions;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\Factory\FactoryInterface;
@@ -31,6 +32,19 @@ class CacheFactory implements FactoryInterface
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$appOptions = $container->get(AppOptions::class);
$adapter = $this->getAdapter($container);
$adapter->setNamespace($appOptions->__toString());
return $adapter;
}
/**
* @param ContainerInterface $container
* @return Cache\CacheProvider
*/
protected function getAdapter(ContainerInterface $container)
{
// Try to get the adapter from config
$config = $container->get('config');
@@ -47,7 +61,7 @@ class CacheFactory implements FactoryInterface
/**
* @param array $cacheConfig
* @return Cache\Cache
* @return Cache\CacheProvider
*/
protected function resolveCacheAdapter(array $cacheConfig)
{