5 use Doctrine\Common\Cache\Cache;
10 use Zend\Cache\Storage\StorageInterface;
27 if (!is_object($cache)) {
33 } elseif ($cache instanceof Cache) {
35 } elseif ($cache instanceof StorageInterface) {
52 public static function factory($config = array())
55 if (!is_array($config)) {
59 if (!isset($config[
'cache.adapter']) && !isset($config[
'cache.provider'])) {
60 $config[
'cache.adapter'] =
'Guzzle\Cache\NullCacheAdapter';
61 $config[
'cache.provider'] =
null;
64 foreach (array(
'cache.adapter',
'cache.provider') as $required) {
65 if (!isset($config[$required])) {
68 if (is_string($config[$required])) {
70 $config[$required] = str_replace(
'.',
'\\', $config[$required]);
71 if (!class_exists($config[$required])) {
77 if (is_string($config[
'cache.provider'])) {
78 $args = isset($config[
'cache.provider.args']) ? $config[
'cache.provider.args'] :
null;
79 $config[
'cache.provider'] = self::createObject($config[
'cache.provider'], $args);
84 if (is_string($config[
'cache.adapter'])) {
85 $args = isset($config[
'cache.adapter.args']) ? $config[
'cache.adapter.args'] : array();
86 array_unshift($args, $config[
'cache.provider']);
87 $config[
'cache.adapter'] = self::createObject($config[
'cache.adapter'], $args);
90 return $config[
'cache.adapter'];
104 private static function createObject($className, array $args =
null)
108 return new $className;
110 $c = new \ReflectionClass($className);
111 return $c->newInstanceArgs($args);
113 }
catch (\Exception $e) {
114 throw new RuntimeException($e->getMessage(), $e->getCode(), $e);