ClanCats Logo

Container

ClanCats Container Usage

This document focuses more on the public API of the default container instance.

For more basic usage check:


Parameters

Think of parameters as mostly scalar configuration values that can be injected inside your dependencies.


Construct with parameters

Bla Bla


Getting a parameter

Get the parameter with the the given name, or return the default value if the parameter is not set.

Method definition:

public function getParameter(string $name, $default = null)
Data type Variable name Comment
string $name The parameter name.
mixed $default The returned default value if the parameter is not set.

Returns

mixed


Setting a parameter

Set the given parameter with value

Method definition:

public function setParameter(string $name, $value)
Data type Variable name Comment
string $name The parameter name.
mixed $value The parameter value.

Returns

void


Check if parameter exists

Does the container contain the parameter with the given name?

Method definition:

public function hasParameter(string $name) : bool
Data type Variable name Comment
string $name The parameter name.

Returns

bool


Services


Binding a service

Attention: There is more! check out Service binding basics.


Getting a service

Retrieve a service from the container.

Method definition:

public function get(string $serviceName)
Data type Variable name Comment
string $serviceName The name / Identifier of the service to look for.

Returns

mixed

The requested service.


Available services

Returns an array of all available servic keys.

Method definition:

public function available() : array

Returns

array[string]


Has service

Does the container have the given service?

Method definition:

public function has(string $serviceName) : bool
Data type Variable name Comment
string $serviceName The name / Identifier of the service to look for.

Returns

bool


Set service

Sets a value on the container instance. This will overwrite any service stored / shared under the same name.

Method definition:

public function set(string $serviceName, $serviceValue)
Data type Variable name Comment
string $serviceName The name / Identifier of the service to look for.
mixed $serviceValue

Returns

void


Remove service

Removes a service from the container and releases the shared instance if it has been loaded.

Method definition:

public function remove(string $serviceName) : bool
Data type Variable name Comment
string $serviceName The name / Identifier of the service to look for.

Returns

bool

Returns true if the service has been removed.


Release service

Release a shared resolved service from the container. This will force the service to reload when accessed again.

Method definition:

public function release(string $serviceName) : bool
Data type Variable name Comment
string $serviceName

Returns

bool

Return false on failure.


Is service resolved

Check if the given service has already been resolved / shared / initiated. A factory service will always return false.

Method definition:

public function isResolved(string $serviceName) : bool
Data type Variable name Comment
string $serviceName The name / Identifier of the service to look for.

Returns

bool