This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
/
StorageCacheAbstractFactory.php
57 lines (51 loc) · 1.84 KB
/
StorageCacheAbstractFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Cache\Service;
use Zend\Cache\StorageFactory;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Storage cache factory for multiple caches.
*/
class StorageCacheAbstractFactory implements AbstractFactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @param string $name
* @param string $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
if ('cache\\' !== substr(strtolower($requestedName), 0, 6)) {
return false;
}
$config = $serviceLocator->get('Config');
if (!isset($config['caches'])) {
return false;
}
$config = array_change_key_case($config['caches']);
$service = substr(strtolower($requestedName), 6);
return isset($config[$service]) && is_array($config[$service]);
}
/**
* @param ServiceLocatorInterface $serviceLocator
* @param string $name
* @param string $requestedName
* @return \Zend\Cache\Storage\StorageInterface
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$config = $serviceLocator->get('Config');
$config = array_change_key_case($config['caches']);
$service = substr(strtolower($requestedName), 6);
$cacheConfig = $config[$service];
return StorageFactory::factory($cacheConfig);
}
}