Browse Source

Deprecate $plugin property in favor of $request->getParam('plugin').

Robert Pustułka 8 years ago
parent
commit
40f9b4e051
2 changed files with 6 additions and 42 deletions
  1. 5 26
      src/Controller/Controller.php
  2. 1 16
      tests/TestCase/Controller/ControllerTest.php

+ 5 - 26
src/Controller/Controller.php

@@ -212,8 +212,9 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
      * Automatically set to the name of a plugin.
      * Automatically set to the name of a plugin.
      *
      *
      * @var string
      * @var string
+     * @deprecated 3.5.0 Use `$this->request->getParam('plugin')` instead.
      */
      */
-    protected $plugin;
+    public $plugin;
 
 
     /**
     /**
      * Holds all passed params.
      * Holds all passed params.
@@ -252,14 +253,15 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
         }
         }
 
 
         $this->setRequest($request !== null ? $request : new ServerRequest());
         $this->setRequest($request !== null ? $request : new ServerRequest());
-        $this->response = $response !== null ? $response : new Response();
+        $this->setResponse($response !== null ? $response : new Response());
 
 
         if ($eventManager !== null) {
         if ($eventManager !== null) {
             $this->setEventManager($eventManager);
             $this->setEventManager($eventManager);
         }
         }
 
 
         $this->modelFactory('Table', [$this->getTableLocator(), 'get']);
         $this->modelFactory('Table', [$this->getTableLocator(), 'get']);
-        $modelClass = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
+        $plugin = $this->request->getParam('plugin');
+        $modelClass = ($plugin ? $plugin . '.' : '') . $this->name;
         $this->_setModelClass($modelClass);
         $this->_setModelClass($modelClass);
 
 
         if ($components !== null) {
         if ($components !== null) {
@@ -440,29 +442,6 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
     }
     }
 
 
     /**
     /**
-     * Returns the controller plugin name.
-     *
-     * @return string
-     */
-    public function getPlugin()
-    {
-        return $this->plugin;
-    }
-
-    /**
-     * Sets the controller plugin name.
-     *
-     * @param string $plugin Controller plugin name.
-     * @return $this
-     */
-    public function setPlugin($plugin)
-    {
-        $this->plugin = $plugin;
-
-        return $this;
-    }
-
-    /**
      * Returns true if an action should be rendered automatically.
      * Returns true if an action should be rendered automatically.
      *
      *
      * @return bool
      * @return bool

+ 1 - 16
tests/TestCase/Controller/ControllerTest.php

@@ -1100,20 +1100,6 @@ class ControllerTest extends TestCase
     }
     }
 
 
     /**
     /**
-     * Test plugin getter and setter.
-     *
-     * @return void
-     */
-    public function testPlugin()
-    {
-        $controller = new PostsController();
-        $this->assertNull($controller->getPlugin());
-
-        $this->assertSame($controller, $controller->setPlugin('Posts'));
-        $this->assertEquals('Posts', $controller->getPlugin());
-    }
-
-    /**
      * Test request getter and setter.
      * Test request getter and setter.
      *
      *
      * @return void
      * @return void
@@ -1135,7 +1121,7 @@ class ControllerTest extends TestCase
         $this->assertSame($controller, $controller->setRequest($request));
         $this->assertSame($controller, $controller->setRequest($request));
         $this->assertSame($request, $controller->getRequest());
         $this->assertSame($request, $controller->getRequest());
 
 
-        $this->assertEquals('Posts', $controller->getPlugin());
+        $this->assertEquals('Posts', $controller->getRequest()->getParam('plugin'));
         $this->assertEquals(['foo', 'bar'], $controller->passedArgs);
         $this->assertEquals(['foo', 'bar'], $controller->passedArgs);
     }
     }
 
 
@@ -1209,7 +1195,6 @@ class ControllerTest extends TestCase
     {
     {
         return [
         return [
             ['name', 'getName', 'setName', 'Foo'],
             ['name', 'getName', 'setName', 'Foo'],
-            ['plugin', 'getPlugin', 'setPlugin', 'Foo'],
             ['autoRender', 'isAutoRenderEnabled', 'enableAutoRender/disableAutoRender', false],
             ['autoRender', 'isAutoRenderEnabled', 'enableAutoRender/disableAutoRender', false],
         ];
         ];
     }
     }