From: Kunal Mehta Date: Thu, 6 Jun 2019 01:12:45 +0000 (-0400) Subject: Have ServiceContainer implement PSR-11 X-Git-Tag: 1.34.0-rc.0~1456^2 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=73cea62869b0fff95ee1017e969e5fccb7e8e4a8;p=lhc%2Fweb%2Fwiklou.git Have ServiceContainer implement PSR-11 Bug: T222410 Change-Id: Ifab2602972ba385a975a0d8279605d2c4802ca9f Depends-On: I5629e287208b2f038753d88d328989ebdc934c0f --- diff --git a/composer.json b/composer.json index 751da3fe8a..e2244122d5 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/includes/libs/services/CannotReplaceActiveServiceException.php b/includes/libs/services/CannotReplaceActiveServiceException.php index aae2700af1..e139529e46 100644 --- a/includes/libs/services/CannotReplaceActiveServiceException.php +++ b/includes/libs/services/CannotReplaceActiveServiceException.php @@ -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 diff --git a/includes/libs/services/ContainerDisabledException.php b/includes/libs/services/ContainerDisabledException.php index 66fe97a233..11a4d3d08f 100644 --- a/includes/libs/services/ContainerDisabledException.php +++ b/includes/libs/services/ContainerDisabledException.php @@ -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 diff --git a/includes/libs/services/NoSuchServiceException.php b/includes/libs/services/NoSuchServiceException.php index da510814f8..b6146ab901 100644 --- a/includes/libs/services/NoSuchServiceException.php +++ b/includes/libs/services/NoSuchServiceException.php @@ -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 diff --git a/includes/libs/services/ServiceAlreadyDefinedException.php b/includes/libs/services/ServiceAlreadyDefinedException.php index 339b8a11d5..7b53cb8fdb 100644 --- a/includes/libs/services/ServiceAlreadyDefinedException.php +++ b/includes/libs/services/ServiceAlreadyDefinedException.php @@ -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 diff --git a/includes/libs/services/ServiceContainer.php b/includes/libs/services/ServiceContainer.php index dd0d081854..d1f10524d5 100644 --- a/includes/libs/services/ServiceContainer.php +++ b/includes/libs/services/ServiceContainer.php @@ -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 * diff --git a/includes/libs/services/ServiceDisabledException.php b/includes/libs/services/ServiceDisabledException.php index fabe1b3c30..bdca5181f1 100644 --- a/includes/libs/services/ServiceDisabledException.php +++ b/includes/libs/services/ServiceDisabledException.php @@ -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