Updated mediawiki/extensions
Project: mediawiki/extensions/SemanticMediaWiki  b8a26c386e57d8ddfcb1fe090198cbec1f567929

\SMW\SimpleDependencyBuilder + \SMW\DependencyInjector

A basic framework to enable dependency injection in Semantic MediaWiki for
immutable or service objects to be injected independently into a client.

\SMW\SimpleDependencyBuilder
Code coverage: 100%
CRAP: 18

\SMW\DependencyInjector
Code coverage: 100%
CRAP: 2

\SMW\CommonDependencyContainer
Code coverage: 100%
CRAP: 3

\SMW\DependencyContainerBase
Code coverage: 100%
CRAP: 8

* Support of predefined DependencyContainer
* Support to register of multiple container
* Support to create objects using eager or lazy loading
* Support for "named" constructor arguments

== DependencyContainer ==
* DependencyObject an interface that specifies a method to register a dependency
object
* DependencyContainer an interface that specifies all necessary methods required
by a container
* DependencyContainerBase abstract class implementing the ObjectStorage

=== EmptyDependencyContainer class ===
An empty container that is also used as default container for when
SimpleDependencyBuilder does not invoke a constructor object.

<pre>
$container = new EmptyDependencyContainer();

// Eager loading
$container->someFunnyTitle = $this->newTitle();

// Lazy loading
$container->diwikipage = function ( DependencyBuilder $builder ) {
	return DIWikiPage::newFromTitle( $builder->getArgument( 'Title' ) );
};

$container->registerObject( 'Foo', new \stdClass );

// Access objects through a builder
$builder = new SimpleDependencyBuilder( $container );

$builder->newObject( 'Foo' );
$builder->newObject( 'someFunnyTitle ' );

$builder->addArgument( 'Title', $builder->newObject( 'someFunnyTitle' ) );
$builder->newObject( 'diwikipage' );
</pre>

=== CommonDependencyContainer class ===
Implementation of the DependencyContainer to provide common objects used
during Semantic MediaWiki's life cycle.

<pre>
$builder = new SimpleDependencyBuilder( new CommonDependencyContainer () );
$builder->newObject( 'Settings' );
$builder->newObject( 'Title' );
...
</pre>

== DependencyBuilder  ==
* DependencyFactory an interface that specifies a method to create a new object
* DependencyBuilder an interface that extends DependencyFactory and specifies
the registration process as well as methods to access constructor arguments.

=== SimpleDependencyBuilder class ===
Implementation of the DependencyBuilder to access DI objects and its invoked arguments.

<pre>
// Register container
$builder = new SimpleDependencyBuilder();
$builder->registerContainer( new EmptyDependencyContainer() );

// Register objects though the container
$builder->getContainer()->registerObject( 'DIWikiPage', function ( DependencyBuilder $builder ) {
	return DIWikiPage::newFromTitle( $builder->getArgument( 'Title' ) );
} );

// Object instantiation
$diWikiPage = $builder->newObject( 'DIWikiPage', array( $title ) ) or
$diWikiPage = $builder->addArgument( 'Title', $title )->newObject( 'DIWikiPage' );
</pre>

== DependencyInjector ==
* DependencyRequestor an interface that specifies methods to access a
DependencyBuilder within a client that requests dependency injection.
* DependencyInjector an abstract class that implements the DependencyRequestor
to enable convenience access to an injected DependencyBuilder

<pre>
$articlePurge = new ArticlePurge( ... );

$articlePurge->setDependencyBuilder( new SimpleDependencyBuilder(
	new CommonDependencyContainer()
) )

$articlePurge->getDependencyBuilder()->newObject( 'Foo' );
</pre>

## Example
Example implementation of the DI framework in \SMW\ArticlePurge

## Example injection process
SMW\ArticlePurge->process( )
SMW\SimpleDependencyBuilder->newObject( )
SMW\SimpleDependencyBuilder->build( )
SMW\CommonDependencyContainer->SMW\{closure}( )

Change-Id: I1d5e7a6ea94270659c696f04fe7bc4d9539f32cd