\OCPIContainer

Class IContainer

IContainer is the basic interface to be used for any internal dependency injection mechanism

Summary

Methods
Constants
resolve()
query()
registerParameter()
registerService()
registerAlias()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

resolve()

resolve(string  $name) : \stdClass

If a parameter is not registered in the container try to instantiate it by using reflection to find out how to build the class

Parameters

string $name

the class name to resolve

Throws

\OCP\AppFramework\QueryException

if the class could not be found or instantiated

Returns

\stdClass

query()

query(string  $name) : mixed

Look up a service for a given name in the container.

Parameters

string $name

Returns

mixed

registerParameter()

registerParameter(string  $name, mixed  $value) : void

A value is stored in the container with it's corresponding name

Parameters

string $name
mixed $value

registerService()

registerService(string  $name, \Closure  $closure, boolean  $shared = true) : void

A service is registered in the container where a closure is passed in which will actually create the service on demand.

In case the parameter $shared is set to true (the default usage) the once created service will remain in memory and be reused on subsequent calls. In case the parameter is false the service will be recreated on every call.

Parameters

string $name
\Closure $closure
boolean $shared

registerAlias()

registerAlias(string  $alias, string  $target) 

Shortcut for returning a service from a service under a different key, e.g. to tell the container to return a class when queried for an interface

Parameters

string $alias

the alias that should be registered

string $target

the target that should be resolved instead