|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @link http://github.com/zendframework/zend-cache for the canonical source repository |
| 4 | + * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) |
| 5 | + * @license http://framework.zend.com/license/new-bsd New BSD License |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Zend\Cache\Service; |
| 9 | + |
| 10 | +use Interop\Container\ContainerInterface; |
| 11 | +use Zend\Cache\StorageFactory; |
| 12 | +use Zend\Cache\Storage\AdapterPluginManager; |
| 13 | +use Zend\Cache\Storage\PluginManager; |
| 14 | + |
| 15 | +trait PluginManagerLookupTrait |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Prepare the storage factory with the adapter and plugins plugin managers. |
| 19 | + * |
| 20 | + * @param ContainerInterface $container |
| 21 | + * @return void |
| 22 | + */ |
| 23 | + private function prepareStorageFactory(ContainerInterface $container) |
| 24 | + { |
| 25 | + StorageFactory::setAdapterPluginManager($this->lookupStorageAdapterPluginManager($container)); |
| 26 | + StorageFactory::setPluginManager($this->lookupStoragePluginManager($container)); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Lookup the storage adapter plugin manager. |
| 31 | + * |
| 32 | + * Returns the Zend\Cache\Storage\AdapterPluginManager service if present, |
| 33 | + * or creates a new instance otherwise. |
| 34 | + * |
| 35 | + * @param ContainerInterface $container |
| 36 | + * @return AdapterPluginManager |
| 37 | + */ |
| 38 | + private function lookupStorageAdapterPluginManager(ContainerInterface $container) |
| 39 | + { |
| 40 | + if ($container->has(AdapterPluginManager::class)) { |
| 41 | + return $container->get(AdapterPluginManager::class); |
| 42 | + } |
| 43 | + return new AdapterPluginManager($container); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Lookup the storage plugins plugin manager. |
| 48 | + * |
| 49 | + * Returns the Zend\Cache\Storage\PluginManager service if present, or |
| 50 | + * creates a new instance otherwise. |
| 51 | + * |
| 52 | + * @param ContainerInterface $container |
| 53 | + * @return PluginManager |
| 54 | + */ |
| 55 | + private function lookupStoragePluginManager(ContainerInterface $container) |
| 56 | + { |
| 57 | + if ($container->has(PluginManager::class)) { |
| 58 | + return $container->get(PluginManager::class); |
| 59 | + } |
| 60 | + return new PluginManager($container); |
| 61 | + } |
| 62 | +} |
0 commit comments