Container class

class Slick\Di\Container

Container is where your dependencies live. It holds a list of DefinitionInterface objects that can be resolved into objects or values.


Finds an entry of the container by its identifier and returns it.

  • $id (string) – Identifier of the entry to look for.

NotFoundException – No entry was found for this identifier.


An object or value that was stored or has its definition under the provided $id identifier.


Returns true if the container can return an entry for the given identifier

  • $id (string) – Identifier of the entry to look for.

True if container can return an entry or false otherwise.

Slick\Di\Container::register($name, $definition[, $scope, $params])

Adds a definition or a value to the container with the $name as identifier.

  • $name (string) – Identifier where the entry will be stored in.
  • $definition (mixed) – The definition or value to store.
  • $scope (string|Scope) – The resolution scope. Please see Definitions page for details. Defaults to Scope::SINGLETON.
  • $params (array) – An array of arguments to pass to callable (Factory) definitions. Defaults to an empty array.

Container itself. Useful for chaining more container calls.


$definition can be any value and the container will evaluate it in order to determine what strategy it will use to resolve it latter on. The possibilities are:

  • scalar|objects: scalar values or objects are store as Value definition;
  • @<identifier>: this is an Alias definition that will point to the definition stored under the identifier name;
  • callable: a callable is stored as Factory definition. It will be executed when Container::get() is called for the first time and the result value will be returned in the subsequent calls. $params will be passed when executing the callable;
  • Slick\Di\DefinitionInterface: Definition interface handle the entry resolution. In this case the container will return the resolved value of the definition.
Slick\Di\Container::make($className[, ...$arguments])

Creates an instance of provided class injecting its dependencies.

  • $className (string) – The class name that the container will use to create the object.
  • $arguments (array) – An optional list of arguments to pass to the constructor.

An object from the type passed in the $className argument.


If you create a class that implements the Slick\Di\ContainerInjectionInterface all the $arguments that you may pass to this method will be ignored as the container will call the create() method and pass himself as an argument to that method. Please see ContainerInjectionInterface reference