Skip to content

Commit 03008f9

Browse files
committed
- Suggested fix for duplicate filters
1 parent bd01ff9 commit 03008f9

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/AssetManager/Service/AssetFilterManager.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ class AssetFilterManager implements ServiceLocatorAwareInterface, MimeResolverAw
2525
* @var MimeResolver
2626
*/
2727
protected $mimeResolver;
28-
28+
29+
/**
30+
*
31+
* @var array Filters already instanced
32+
*/
33+
34+
protected $filterInstances;
35+
2936
/**
3037
* Construct the AssetFilterManager
3138
*
@@ -35,6 +42,7 @@ class AssetFilterManager implements ServiceLocatorAwareInterface, MimeResolverAw
3542
public function __construct(array $config = array())
3643
{
3744
$this->setConfig($config);
45+
$this->setFilterInstances(array());
3846
}
3947

4048
/**
@@ -144,8 +152,14 @@ protected function ensureByFilter(AssetInterface $asset, $filter)
144152
'No filter found for ' . $filter
145153
);
146154
}
147-
148-
$filterInstance = new $filterClass;
155+
156+
if (!array_key_exists($filterClass, $this->filterInstances)) {
157+
$filterInstance = new $filterClass;
158+
$this->filterInstances[$filterClass] = $filterInstance;
159+
}
160+
else {
161+
$filterInstance = $this->filterInstances[$filterClass];
162+
}
149163

150164
$asset->ensureFilter($filterInstance);
151165
}
@@ -181,4 +195,24 @@ public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
181195
{
182196
$this->serviceLocator = $serviceLocator;
183197
}
198+
199+
/**
200+
* Returns the array of filter instances
201+
*
202+
* @return array
203+
*/
204+
public function getFilterInstances() {
205+
return $this->filterInstances;
206+
}
207+
208+
/**
209+
* Sets the array of filter instances
210+
*
211+
* @param array $filterInstances
212+
*/
213+
public function setFilterInstances($filterInstances) {
214+
$this->filterInstances = $filterInstances;
215+
}
216+
217+
184218
}

0 commit comments

Comments
 (0)