From 684365e8c932d489a6ad700d2f42b5a845c601f7 Mon Sep 17 00:00:00 2001
From: Klimov Paul <klimov.paul@gmail.com>
Date: Wed, 17 Sep 2014 13:10:12 +0300
Subject: [PATCH] Fixed `yii\console\controllers\CacheController` does not check if cache component instance of 'yii\caching\Cache'

close #5055
---
 framework/CHANGELOG.md                                           |  1 +
 framework/console/controllers/CacheController.php                | 14 ++++++++++++--
 tests/unit/framework/console/controllers/CacheControllerTest.php |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md
index 527eb1c..175ee5b 100644
--- a/framework/CHANGELOG.md
+++ b/framework/CHANGELOG.md
@@ -98,6 +98,7 @@ Yii Framework 2 Change Log
 - Bug #5001: `yii\rest\CreateAction`, `yii\rest\UpdateAction` and `yii\rest\DeleteAction` should throw 500 error if the model operation returns false without validation errors (qiangxue)
 - Bug #5039: `UniqueValidator` and `ExistValidator` did not respect query conditions added by default scope (qiangxue)
 - Bug #5049: `ActiveForm::validationDelay` should be applied to user types only (qiangxue)
+- Bug #5055: Fixed `yii\console\controllers\CacheController` does not check if cache component instance of 'yii\caching\Cache' (klimov-paul)
 - Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark)
 - Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul)
 - Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
diff --git a/framework/console/controllers/CacheController.php b/framework/console/controllers/CacheController.php
index ac60868..2548194 100644
--- a/framework/console/controllers/CacheController.php
+++ b/framework/console/controllers/CacheController.php
@@ -212,9 +212,9 @@ class CacheController extends Controller
 
             if ($component instanceof Cache) {
                 $caches[$name] = get_class($component);
-            } elseif (is_array($component) && isset($component['class']) && strpos($component['class'], 'Cache') !== false) {
+            } elseif (is_array($component) && isset($component['class']) && $this->isCacheClass($component['class'])) {
                 $caches[$name] = $component['class'];
-            } elseif (is_string($component) && strpos($component, 'Cache') !== false) {
+            } elseif (is_string($component) && $this->isCacheClass($component)) {
                 $caches[$name] = $component;
             }
         }
@@ -222,4 +222,14 @@ class CacheController extends Controller
         return $caches;
     }
 
+    /**
+     * Checks if given class is a Cache class.
+     * @param string $className class name.
+     * @return boolean
+     */
+    private function isCacheClass($className)
+    {
+        return is_subclass_of($className, Cache::className());
+    }
+
 }
diff --git a/tests/unit/framework/console/controllers/CacheControllerTest.php b/tests/unit/framework/console/controllers/CacheControllerTest.php
index 5947a83..600b38a 100644
--- a/tests/unit/framework/console/controllers/CacheControllerTest.php
+++ b/tests/unit/framework/console/controllers/CacheControllerTest.php
@@ -33,6 +33,7 @@ class CacheControllerTest extends TestCase
             'components' => [
                 'firstCache' => 'yii\caching\ArrayCache',
                 'secondCache' => 'yii\caching\ArrayCache',
+                'session' => 'yii\web\CacheSession', // should be ignored at `actionFlushAll()`
             ],
         ]);
     }
--
libgit2 0.27.1