Revert "Use display name in category page subheadings if provided"
[lhc/web/wiklou.git] / includes / Services / ServiceContainer.php
index 66ee918..bad0ef9 100644 (file)
@@ -55,6 +55,11 @@ class ServiceContainer implements DestructibleService {
         */
        private $serviceInstantiators = [];
 
+       /**
+        * @var boolean[] disabled status, per service name
+        */
+       private $disabled = [];
+
        /**
         * @var array
         */
@@ -126,6 +131,28 @@ class ServiceContainer implements DestructibleService {
                }
        }
 
+       /**
+        * Imports all wiring defined in $container. Wiring defined in $container
+        * will override any wiring already defined locally. However, already
+        * existing service instances will be preserved.
+        *
+        * @since 1.28
+        *
+        * @param ServiceContainer $container
+        * @param string[] $skip A list of service names to skip during import
+        */
+       public function importWiring( ServiceContainer $container, $skip = [] ) {
+               $newInstantiators = array_diff_key(
+                       $container->serviceInstantiators,
+                       array_flip( $skip )
+               );
+
+               $this->serviceInstantiators = array_merge(
+                       $this->serviceInstantiators,
+                       $newInstantiators
+               );
+       }
+
        /**
         * Returns true if a service is defined for $name, that is, if a call to getService( $name )
         * would return a service instance.
@@ -220,6 +247,7 @@ class ServiceContainer implements DestructibleService {
                }
 
                $this->serviceInstantiators[$name] = $instantiator;
+               unset( $this->disabled[$name] );
        }
 
        /**
@@ -244,9 +272,7 @@ class ServiceContainer implements DestructibleService {
        public function disableService( $name ) {
                $this->resetService( $name );
 
-               $this->redefineService( $name, function() use ( $name ) {
-                       throw new ServiceDisabledException( $name );
-               } );
+               $this->disabled[$name] = true;
        }
 
        /**
@@ -282,6 +308,7 @@ class ServiceContainer implements DestructibleService {
                }
 
                unset( $this->services[$name] );
+               unset( $this->disabled[$name] );
        }
 
        /**
@@ -299,7 +326,8 @@ class ServiceContainer implements DestructibleService {
         * @param string $name The service name
         *
         * @throws NoSuchServiceException if $name is not a known service.
-        * @throws ServiceDisabledException if this container has already been destroyed.
+        * @throws ContainerDisabledException if this container has already been destroyed.
+        * @throws ServiceDisabledException if the requested service has been disabled.
         *
         * @return object The service instance
         */
@@ -308,6 +336,10 @@ class ServiceContainer implements DestructibleService {
                        throw new ContainerDisabledException();
                }
 
+               if ( isset( $this->disabled[$name] ) ) {
+                       throw new ServiceDisabledException( $name );
+               }
+
                if ( !isset( $this->services[$name] ) ) {
                        $this->services[$name] = $this->createService( $name );
                }
@@ -327,6 +359,7 @@ class ServiceContainer implements DestructibleService {
                                $this->serviceInstantiators[$name],
                                array_merge( [ $this ], $this->extraInstantiationParams )
                        );
+                       // NOTE: when adding more wiring logic here, make sure copyWiring() is kept in sync!
                } else {
                        throw new NoSuchServiceException( $name );
                }
@@ -334,4 +367,12 @@ class ServiceContainer implements DestructibleService {
                return $service;
        }
 
+       /**
+        * @param string $name
+        * @return bool Whether the service is disabled
+        * @since 1.28
+        */
+       public function isServiceDisabled( $name ) {
+               return isset( $this->disabled[$name] );
+       }
 }