4 use InvalidArgumentException;
6 use Wikimedia\Assert\Assert;
106 $this->serviceInstantiators = [];
108 $this->services = [];
109 $this->destroyed =
true;
118 foreach ( $wiringFiles
as $file ) {
120 $wiring = require $file;
122 Assert::postcondition(
124 "Wiring file $file is expected to return an array!"
156 $newInstantiators = array_diff_key(
157 $container->serviceInstantiators,
161 $this->serviceInstantiators = array_merge(
162 $this->serviceInstantiators,
166 $newManipulators = array_diff(
167 array_keys( $container->serviceManipulators ),
171 foreach ( $newManipulators
as $name ) {
172 if ( isset( $this->serviceManipulators[
$name] ) ) {
173 $this->serviceManipulators[
$name] = array_merge(
174 $this->serviceManipulators[
$name],
175 $container->serviceManipulators[
$name]
178 $this->serviceManipulators[
$name] = $container->serviceManipulators[
$name];
192 return isset( $this->serviceInstantiators[
$name] );
215 return $this->services[
$name] ??
null;
222 return array_keys( $this->serviceInstantiators );
240 Assert::parameterType(
'string',
$name,
'$name' );
246 $this->serviceInstantiators[
$name] = $instantiator;
269 Assert::parameterType(
'string',
$name,
'$name' );
275 if ( isset( $this->services[
$name] ) ) {
279 $this->serviceInstantiators[
$name] = $instantiator;
280 unset( $this->disabled[
$name] );
310 Assert::parameterType(
'string',
$name,
'$name' );
316 if ( isset( $this->services[
$name] ) ) {
320 $this->serviceManipulators[
$name][] = $manipulator;
345 $this->disabled[
$name] =
true;
372 Assert::parameterType(
'string',
$name,
'$name' );
377 $instance->destroy();
380 unset( $this->services[
$name] );
381 unset( $this->disabled[
$name] );
405 if ( $this->destroyed ) {
409 if ( isset( $this->disabled[
$name] ) ) {
413 if ( !isset( $this->services[
$name] ) ) {
417 return $this->services[
$name];
427 if ( isset( $this->serviceInstantiators[
$name] ) ) {
428 $service = ( $this->serviceInstantiators[
$name] )(
430 ...$this->extraInstantiationParams
433 if ( isset( $this->serviceManipulators[
$name] ) ) {
434 foreach ( $this->serviceManipulators[
$name]
as $callback ) {
435 $ret = call_user_func_array(
437 array_merge( [ $service, $this ], $this->extraInstantiationParams )
443 if (
$ret !==
null ) {
463 return isset( $this->disabled[
$name] );