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#52
Parent:Psr\Container\ContainerInterface

Methods

public OCP\IContainer::resolve($name)
Source:

lib/public/IContainer.php#68

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

\stdClass

Since:

8.2.0

Deprecated:

20.0.0 use \Psr\Container\ContainerInterface::get

Throws:

\Psr\Container\ContainerExceptionInterface if the class could not be found or instantiated

Throws:

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

Throws:

\Psr\Container\ContainerExceptionInterface if the class could not be found or instantiated

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#85

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:

\Psr\Container\ContainerExceptionInterface if the query could not be resolved

Throws:

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

Throws:

\Psr\Container\ContainerExceptionInterface if the query could not be resolved

Throws:

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

Since:

6.0.0

Deprecated:

20.0.0 use \Psr\Container\ContainerInterface::get

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

lib/public/IContainer.php#96

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

void

Since:

6.0.0

Deprecated:

20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter

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#112

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

void

Since:

6.0.0

Deprecated:

20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService

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#123

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

8.2.0

Deprecated:

20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias