Skip to content

Commit 2ddc90d

Browse files
author
Westin Shafer
committed
Added missing doc blocks.
Removed unneeded doc blocks Moved config to constructor + factory and updated unit tests for the asset cache manager. Changed order for asset cache provider discovery and return from method as soon as resource is found.
1 parent ab6ca79 commit 2ddc90d

File tree

4 files changed

+123
-186
lines changed

4 files changed

+123
-186
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ clover.xml
22
php-cs-fixer.phar
33
composer.json
44
composer.lock
5-
vendor
5+
vendor
6+
.idea

src/AssetManager/Service/AssetCacheManager.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
/**
1111
* Asset Cache Manager. Sets asset cache based on configuration.
12-
*
13-
* @category AssetManager
14-
* @package AssetManager
1512
*/
1613
class AssetCacheManager
1714
{
15+
/**
16+
* @var \Zend\ServiceManager\ServiceLocatorInterface
17+
*/
1818
protected $serviceLocator;
1919

2020
/**
@@ -26,18 +26,16 @@ class AssetCacheManager
2626
* Construct the AssetCacheManager
2727
*
2828
* @param ServiceLocatorInterface $serviceLocator
29+
* @param array $config
2930
*
3031
* @return AssetCacheManager
3132
*/
32-
public function __construct(ServiceLocatorInterface $serviceLocator)
33-
{
33+
public function __construct(
34+
ServiceLocatorInterface $serviceLocator,
35+
$config
36+
) {
3437
$this->serviceLocator = $serviceLocator;
35-
36-
$globalConfig = $this->serviceLocator->get('config');
37-
38-
if (!empty($globalConfig['asset_manager']['caching'])) {
39-
$this->config = $globalConfig['asset_manager']['caching'];
40-
}
38+
$this->config = $config;
4139
}
4240

4341
/**
@@ -79,23 +77,24 @@ private function getProvider($path)
7977
return null;
8078
}
8179

80+
if ($this->serviceLocator->has($cacheProvider['cache'])) {
81+
return $this->serviceLocator->get($cacheProvider['cache']);
82+
}
83+
84+
// Left here for BC. Please consider defining a ZF2 service instead.
8285
if (is_callable($cacheProvider['cache'])) {
83-
$provider = call_user_func($cacheProvider['cache'], $path);
84-
} elseif ($this->serviceLocator->has($cacheProvider['cache'])) {
85-
$provider = $this->serviceLocator->get($cacheProvider['cache']);
86-
} else {
87-
$dir = '';
88-
$class = $cacheProvider['cache'];
89-
90-
if (!empty($cacheProvider['options']['dir'])) {
91-
$dir = $cacheProvider['options']['dir'];
92-
}
93-
94-
$class = $this->classMapper($class);
95-
$provider = new $class($dir, $path);
86+
return call_user_func($cacheProvider['cache'], $path);
87+
}
88+
89+
$dir = '';
90+
$class = $cacheProvider['cache'];
91+
92+
if (!empty($cacheProvider['options']['dir'])) {
93+
$dir = $cacheProvider['options']['dir'];
9694
}
9795

98-
return $provider;
96+
$class = $this->classMapper($class);
97+
return new $class($dir, $path);
9998
}
10099

101100
/**

src/AssetManager/Service/AssetCacheManagerServiceFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ class AssetCacheManagerServiceFactory implements FactoryInterface
1919
*/
2020
public function createService(ServiceLocatorInterface $serviceLocator)
2121
{
22-
return new AssetCacheManager($serviceLocator);
22+
$config = array();
23+
24+
$globalConfig = $serviceLocator->get('config');
25+
26+
if (!empty($globalConfig['asset_manager']['caching'])) {
27+
$config = $globalConfig['asset_manager']['caching'];
28+
}
29+
30+
return new AssetCacheManager($serviceLocator, $config);
2331
}
2432
}

0 commit comments

Comments
 (0)