IContainer

interface OCP\IContainer
Class IContainer
IContainer is the basic interface to be used for any internal dependency injection mechanism
Implemented by:OC\AppFramework\Utility\SimpleContainer
Source:lib/public/IContainer.php#48

Methods

public OCP\IContainer::resolve($name)
If a parameter is not registered in the container try to instantiate it
by using reflection to find out how to build the class
Source:

lib/public/IContainer.php#58

Parameters:
  • $name (string) the class name to resolve
Returns:

\stdClass

Since:

8.2.0

Throws:

\OCP\AppFramework\QueryException if the class could not be found or instantiated

public OCP\IContainer::query($name, $autoload=true)
Look up a service for a given name in the container.
Source:

lib/public/IContainer.php#69

Parameters:
  • $name (string)
  • $autoload (bool) Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example
Returns:

mixed

Throws:

\OCP\AppFramework\QueryException if the query could not be resolved

Since:

6.0.0

public OCP\IContainer::registerParameter($name, $value)
A value is stored in the container with it’s corresponding name
Source:

lib/public/IContainer.php#79

Parameters:
  • $name (string)
  • $value (mixed)
Returns:

void

Since:

6.0.0

public OCP\IContainer::registerService($name, $closure, $shared=true)
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.
Source:

lib/public/IContainer.php#94

Parameters:
  • $name (string)
  • $closure (Closure)
  • $shared (bool)
Returns:

void

Since:

6.0.0

public OCP\IContainer::registerAlias($alias, $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
Source:

lib/public/IContainer.php#104

Parameters:
  • $alias (string) the alias that should be registered
  • $target (string) the target that should be resolved instead
Since:

8.2.0