Browse Source

Merge pull request #7210 from cakephp/is-action

Don't allow overridden methods to count as actions.
José Lorenzo Rodríguez 10 years ago
parent
commit
fd37e91a0d
2 changed files with 15 additions and 3 deletions
  1. 5 3
      src/Controller/Controller.php
  2. 10 0
      tests/TestCase/Controller/ControllerTest.php

+ 5 - 3
src/Controller/Controller.php

@@ -28,6 +28,7 @@ use Cake\Routing\Router;
 use Cake\Utility\MergeVariablesTrait;
 use Cake\View\ViewVarsTrait;
 use LogicException;
+use ReflectionClass;
 use ReflectionException;
 use ReflectionMethod;
 use RuntimeException;
@@ -653,6 +654,10 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
      */
     public function isAction($action)
     {
+        $baseClass = new ReflectionClass('Cake\Controller\Controller');
+        if ($baseClass->hasMethod($action)) {
+            return false;
+        }
         try {
             $method = new ReflectionMethod($this, $action);
         } catch (ReflectionException $e) {
@@ -661,9 +666,6 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
         if (!$method->isPublic()) {
             return false;
         }
-        if ($method->getDeclaringClass()->name === 'Cake\Controller\Controller') {
-            return false;
-        }
         return true;
     }
 

+ 10 - 0
tests/TestCase/Controller/ControllerTest.php

@@ -87,6 +87,16 @@ class TestController extends ControllerTestAppController
     public $modelClass = 'Comments';
 
     /**
+     * beforeFilter handler
+     *
+     * @param \Cake\Event\Event $event
+     * @retun void
+     */
+    public function beforeFilter(Event $event)
+    {
+    }
+
+    /**
      * index method
      *
      * @param mixed $testId