Browse Source

Remove the ability to set component registry instance.

ADmad 3 years ago
parent
commit
c13ff536e7

+ 2 - 15
src/Controller/ComponentRegistry.php

@@ -47,7 +47,8 @@ class ComponentRegistry extends ObjectRegistry implements EventDispatcherInterfa
      */
     public function __construct(Controller $controller)
     {
-        $this->setController($controller);
+        $this->_Controller = $controller;
+        $this->setEventManager($controller->getEventManager());
     }
 
     /**
@@ -61,20 +62,6 @@ class ComponentRegistry extends ObjectRegistry implements EventDispatcherInterfa
     }
 
     /**
-     * Set the controller associated with the collection.
-     *
-     * @param \Cake\Controller\Controller $controller Controller instance.
-     * @return $this
-     */
-    public function setController(Controller $controller)
-    {
-        $this->_Controller = $controller;
-        $this->setEventManager($controller->getEventManager());
-
-        return $this;
-    }
-
-    /**
      * Resolve a component classname.
      *
      * Part of the template method for {@link \Cake\Core\ObjectRegistry::load()}.

+ 1 - 10
src/Controller/Controller.php

@@ -236,19 +236,10 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
     /**
      * Get the component registry for this controller.
      *
-     * If called with the first parameter, it will be set as the controller $this->_components property
-     *
-     * @param \Cake\Controller\ComponentRegistry|null $components Component registry.
      * @return \Cake\Controller\ComponentRegistry
      */
-    public function components(?ComponentRegistry $components = null): ComponentRegistry
+    public function components(): ComponentRegistry
     {
-        if ($components !== null) {
-            $components->setController($this);
-
-            return $this->_components = $components;
-        }
-
         return $this->_components ??= new ComponentRegistry($this);
     }
 

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

@@ -913,25 +913,6 @@ class ControllerTest extends TestCase
     }
 
     /**
-     * Test the components() method with the custom ObjectRegistry.
-     */
-    public function testComponentsWithCustomRegistry(): void
-    {
-        $request = new ServerRequest(['url' => '/']);
-        $componentRegistry = $this->getMockBuilder('Cake\Controller\ComponentRegistry')
-            ->addMethods(['offsetGet'])
-            ->disableOriginalConstructor()
-            ->getMock();
-
-        $controller = new TestController($request);
-        $controller->components($componentRegistry);
-        $this->assertInstanceOf(get_class($componentRegistry), $controller->components());
-
-        $result = $controller->components();
-        $this->assertSame($result, $controller->components());
-    }
-
-    /**
      * Test adding a component
      */
     public function testLoadComponent(): void