From 55c0f4d479f8b8d91dc56fb6c9809cb00b63a52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 8 Sep 2015 17:52:37 +0200 Subject: [PATCH] Fixing #2 using composite exceptions --- composer.json | 3 ++- .../Utils/Cache/Service/PurgeCacheService.php | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 8658586..850012d 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ } ], "require": { - "php": ">=5.3.0" + "php": ">=5.3.0", + "mouf/utils.composite-exception": "~1.0" }, "autoload": { "psr-0": { diff --git a/src/Mouf/Utils/Cache/Service/PurgeCacheService.php b/src/Mouf/Utils/Cache/Service/PurgeCacheService.php index 1e9d043..51174a5 100755 --- a/src/Mouf/Utils/Cache/Service/PurgeCacheService.php +++ b/src/Mouf/Utils/Cache/Service/PurgeCacheService.php @@ -10,6 +10,7 @@ use Mouf\MoufManager; use Mouf\Mvc\Splash\Controllers\Controller; +use Mouf\Utils\CompositeException; /** * This service can purge the cache of ALL cache instances (implementing CacheInterface) declared in Mouf. @@ -23,14 +24,23 @@ public static function purgeAll() { $moufManager = MoufManager::getMoufManager(); $instances = $moufManager->findInstances("Mouf\\Utils\\Cache\\CacheInterface"); - + + $compositeException = new CompositeException(); + foreach ($instances as $instanceName) { - $cacheService = $moufManager->getInstance($instanceName); - /* @var $cacheService CacheInterface */ - - $cacheService->purgeAll(); + try { + $cacheService = $moufManager->getInstance($instanceName); + /* @var $cacheService CacheInterface */ + + $cacheService->purgeAll(); + } catch (\Exception $e) { + $compositeException->add($e); + } + } + + if (!$compositeException->isEmpty()) { + throw $compositeException; } - } }