Browse Source

Update league/container to v4.

Make Cake\Core\ContainerInterface extend League\Container\DefinitionContainerInterface
to satisfying typing requirements.
ADmad 4 years ago
parent
commit
6c2cb80071

+ 1 - 1
composer.json

@@ -30,7 +30,7 @@
         "composer/ca-bundle": "^1.2",
         "laminas/laminas-diactoros": "^2.2.2",
         "laminas/laminas-httphandlerrunner": "^1.1",
-        "league/container": "^3.2",
+        "league/container": "^4.1.1",
         "psr/http-client": "^1.0",
         "psr/http-server-handler": "^1.0",
         "psr/http-server-middleware": "^1.0",

+ 2 - 30
src/Core/ContainerInterface.php

@@ -16,8 +16,7 @@ declare(strict_types=1);
  */
 namespace Cake\Core;
 
-use League\Container\Definition\DefinitionInterface;
-use Psr\Container\ContainerInterface as PsrInterface;
+use League\Container\DefinitionContainerInterface;
 
 /**
  * Interface for the Dependency Injection Container in CakePHP applications
@@ -31,33 +30,6 @@ use Psr\Container\ContainerInterface as PsrInterface;
  * @experimental This interface is not final and can have additional
  *   methods and parameters added in future minor releases.
  */
-interface ContainerInterface extends PsrInterface
+interface ContainerInterface extends DefinitionContainerInterface
 {
-    /**
-     * Add an item to the container.
-     *
-     * @param string $id The class name or name of the service being registered.
-     * @param mixed $concrete Either the classname an interface or name resolves to.
-     *   Can also be a constructed object, Closure, or null. When null, the `$id` parameter will
-     *   be used as the concrete class name.
-     * @param bool $shared Set to true to make a service shared.
-     * @return \League\Container\Definition\DefinitionInterface
-     */
-    public function add(string $id, $concrete = null, bool $shared = false): DefinitionInterface;
-
-    /**
-     * Add a service provider to the container
-     *
-     * @param \League\Container\ServiceProvider\ServiceProviderInterface $provider The service provider to add.
-     * @return $this
-     */
-    public function addServiceProvider($provider);
-
-    /**
-     * Modify an existing definition
-     *
-     * @param string $id The class name or name of the service being modified.
-     * @return \League\Container\Definition\DefinitionInterface
-     */
-    public function extend(string $id): DefinitionInterface;
 }

+ 3 - 3
src/Core/ServiceProvider.php

@@ -18,7 +18,6 @@ namespace Cake\Core;
 
 use League\Container\ServiceProvider\AbstractServiceProvider;
 use League\Container\ServiceProvider\BootableServiceProviderInterface;
-use Psr\Container\ContainerInterface as PsrContainerInterface;
 use RuntimeException;
 
 /**
@@ -42,9 +41,10 @@ abstract class ServiceProvider extends AbstractServiceProvider implements Bootab
      *
      * @return \Cake\Core\ContainerInterface
      */
-    public function getContainer(): PsrContainerInterface
+    public function getContainer(): ContainerInterface
     {
         $container = parent::getContainer();
+
         if (!($container instanceof ContainerInterface)) {
             $message = sprintf(
                 'Unexpected container type. Expected `%s` got `%s` instead.',
@@ -93,7 +93,7 @@ abstract class ServiceProvider extends AbstractServiceProvider implements Bootab
      *
      * @return void
      */
-    public function register()
+    public function register(): void
     {
         $this->services($this->getContainer());
     }

+ 10 - 0
tests/test_app/TestApp/ServiceProvider/PersonServiceProvider.php

@@ -19,4 +19,14 @@ class PersonServiceProvider extends ServiceProvider
     {
         $container->add('sally', json_decode('{"name":"sally"}'));
     }
+
+    public function provides(string $id): bool
+    {
+        $services = [
+            'boot',
+            'sally',
+        ];
+
+        return in_array($id, $services, true);
+    }
 }