Have ServiceContainer implement PSR-11
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 6 Jun 2019 01:12:45 +0000 (21:12 -0400)
committerLegoktm <legoktm@member.fsf.org>
Mon, 10 Jun 2019 16:12:05 +0000 (16:12 +0000)
Bug: T222410
Change-Id: Ifab2602972ba385a975a0d8279605d2c4802ca9f
Depends-On: I5629e287208b2f038753d88d328989ebdc934c0f

composer.json
includes/libs/services/CannotReplaceActiveServiceException.php
includes/libs/services/ContainerDisabledException.php
includes/libs/services/NoSuchServiceException.php
includes/libs/services/ServiceAlreadyDefinedException.php
includes/libs/services/ServiceContainer.php
includes/libs/services/ServiceDisabledException.php

index 751da3f..e224412 100644 (file)
@@ -32,6 +32,7 @@
                "pear/mail_mime": "1.10.2",
                "pear/net_smtp": "1.8.1",
                "php": ">=5.6.99",
+               "psr/container": "1.0.0",
                "psr/log": "1.0.2",
                "wikimedia/assert": "0.2.2",
                "wikimedia/at-ease": "2.0.0",
index aae2700..e139529 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wikimedia\Services;
 
 use Exception;
+use Psr\Container\ContainerExceptionInterface;
 use RuntimeException;
 
 /**
@@ -31,7 +32,8 @@ use RuntimeException;
 /**
  * Exception thrown when trying to replace an already active service.
  */
-class CannotReplaceActiveServiceException extends RuntimeException {
+class CannotReplaceActiveServiceException extends RuntimeException
+       implements ContainerExceptionInterface {
 
        /**
         * @param string $serviceName
index 66fe97a..11a4d3d 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wikimedia\Services;
 
 use Exception;
+use Psr\Container\ContainerExceptionInterface;
 use RuntimeException;
 
 /**
@@ -31,7 +32,8 @@ use RuntimeException;
 /**
  * Exception thrown when trying to access a service on a disabled container or factory.
  */
-class ContainerDisabledException extends RuntimeException {
+class ContainerDisabledException extends RuntimeException
+       implements ContainerExceptionInterface {
 
        /**
         * @param Exception|null $previous
index da51081..b6146ab 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wikimedia\Services;
 
 use Exception;
+use Psr\Container\NotFoundExceptionInterface;
 use RuntimeException;
 
 /**
@@ -31,7 +32,8 @@ use RuntimeException;
 /**
  * Exception thrown when the requested service is not known.
  */
-class NoSuchServiceException extends RuntimeException {
+class NoSuchServiceException extends RuntimeException
+       implements NotFoundExceptionInterface {
 
        /**
         * @param string $serviceName
index 339b8a1..7b53cb8 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wikimedia\Services;
 
 use Exception;
+use Psr\Container\ContainerExceptionInterface;
 use RuntimeException;
 
 /**
@@ -33,7 +34,8 @@ use RuntimeException;
  * Exception thrown when a service was already defined, but the
  * caller expected it to not exist.
  */
-class ServiceAlreadyDefinedException extends RuntimeException {
+class ServiceAlreadyDefinedException extends RuntimeException
+       implements ContainerExceptionInterface {
 
        /**
         * @param string $serviceName
index dd0d081..d1f1052 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wikimedia\Services;
 
 use InvalidArgumentException;
+use Psr\Container\ContainerInterface;
 use RuntimeException;
 use Wikimedia\Assert\Assert;
 
@@ -44,7 +45,7 @@ use Wikimedia\Assert\Assert;
  * @see docs/injection.txt for an overview of using dependency injection in the
  *      MediaWiki code base.
  */
-class ServiceContainer implements DestructibleService {
+class ServiceContainer implements ContainerInterface, DestructibleService {
 
        /**
         * @var object[]
@@ -193,6 +194,11 @@ class ServiceContainer implements DestructibleService {
                return isset( $this->serviceInstantiators[$name] );
        }
 
+       /** @inheritDoc */
+       public function has( $name ) {
+               return $this->hasService( $name );
+       }
+
        /**
         * Returns the service instance for $name only if that service has already been instantiated.
         * This is intended for situations where services get destroyed/cleaned up, so we can
@@ -418,6 +424,11 @@ class ServiceContainer implements DestructibleService {
                return $this->services[$name];
        }
 
+       /** @inheritDoc */
+       public function get( $name ) {
+               return $this->getService( $name );
+       }
+
        /**
         * @param string $name
         *
index fabe1b3..bdca518 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wikimedia\Services;
 
 use Exception;
+use Psr\Container\ContainerExceptionInterface;
 use RuntimeException;
 
 /**
@@ -31,7 +32,8 @@ use RuntimeException;
 /**
  * Exception thrown when trying to access a disabled service.
  */
-class ServiceDisabledException extends RuntimeException {
+class ServiceDisabledException extends RuntimeException
+       implements ContainerExceptionInterface {
 
        /**
         * @param string $serviceName