Browse Source

Change register() to services() for containers

Corey Taylor 5 years ago
parent
commit
f35cfa68ea

+ 2 - 2
src/Core/BasePlugin.php

@@ -55,7 +55,7 @@ class BasePlugin implements PluginInterface
      *
      * @var bool
      */
-    protected $registerEnabled = true;
+    protected $servicesEnabled = true;
 
     /**
      * Load routes or not
@@ -295,7 +295,7 @@ class BasePlugin implements PluginInterface
      * @param \Cake\Core\ContainerInterface $container The container to add services to.
      * @return \Cake\Core\ContainerInterface The updated container
      */
-    public function register(ContainerInterface $container): ContainerInterface
+    public function services(ContainerInterface $container): ContainerInterface
     {
         return $container;
     }

+ 1 - 1
src/Core/ContainerApplicationInterface.php

@@ -34,7 +34,7 @@ interface ContainerApplicationInterface
      * @param \Cake\Core\ContainerInterface $container The container to add services to
      * @return \Cake\Core\ContainerInterface The updated container.
      */
-    public function register(ContainerInterface $container): ContainerInterface;
+    public function services(ContainerInterface $container): ContainerInterface;
 
     /**
      * Create a new container and register services.

+ 2 - 2
src/Core/PluginInterface.php

@@ -21,7 +21,7 @@ use Cake\Routing\RouteBuilder;
 /**
  * Plugin Interface
  *
- * @method \Cake\Core\ContainerInterface register(\Cake\Core\ContainerInterface $container) Register plugin services to
+ * @method \Cake\Core\ContainerInterface services(\Cake\Core\ContainerInterface $container) Register plugin services to
  *   the application's container
  */
 interface PluginInterface
@@ -31,7 +31,7 @@ interface PluginInterface
      *
      * @var string[]
      */
-    public const VALID_HOOKS = ['bootstrap', 'console', 'middleware', 'register', 'routes'];
+    public const VALID_HOOKS = ['bootstrap', 'console', 'middleware', 'routes','services'];
 
     /**
      * Get the name of this plugin.

+ 5 - 5
src/Http/BaseApplication.php

@@ -249,9 +249,9 @@ abstract class BaseApplication implements
         if ($this->container) {
             return $this->container;
         }
-        $container = $this->register(new Container());
-        foreach ($this->plugins->with('register') as $plugin) {
-            $container = $plugin->register($container);
+        $container = $this->services(new Container());
+        foreach ($this->plugins->with('services') as $plugin) {
+            $container = $plugin->services($container);
         }
         $this->container = $container;
 
@@ -259,12 +259,12 @@ abstract class BaseApplication implements
     }
 
     /**
-     * Register application services.
+     * Register application container services.
      *
      * @param \Cake\Core\ContainerInterface $container The Container to update.
      * @return \Cake\Core\ContainerInterface The updated container
      */
-    public function register(ContainerInterface $container): ContainerInterface
+    public function services(ContainerInterface $container): ContainerInterface
     {
         return $container;
     }

+ 2 - 2
tests/TestCase/Core/BasePluginTest.php

@@ -60,7 +60,7 @@ class BasePluginTest extends TestCase
         $this->assertFalse($plugin->isEnabled('bootstrap'));
         $this->assertTrue($plugin->isEnabled('console'));
         $this->assertTrue($plugin->isEnabled('middleware'));
-        $this->assertTrue($plugin->isEnabled('register'));
+        $this->assertTrue($plugin->isEnabled('services'));
     }
 
     public function testGetName()
@@ -96,7 +96,7 @@ class BasePluginTest extends TestCase
     {
         $plugin = new BasePlugin();
         $container = new Container();
-        $this->assertSame($container, $plugin->register($container));
+        $this->assertSame($container, $plugin->services($container));
     }
 
     public function testConsoleFind()

+ 1 - 1
tests/test_app/TestApp/Application.php

@@ -98,7 +98,7 @@ class Application extends BaseApplication
      * @param \Cake\Core\ContainerInterface $container The container to update
      * @return \Cake\Core\ContainerInterface
      */
-    public function register(ContainerInterface $container): ContainerInterface
+    public function services(ContainerInterface $container): ContainerInterface
     {
         $container->add(stdClass::class, json_decode('{"key":"value"}'));