ServiceContainerInterface
interface ServiceContainerInterface
A simple service container interface
The "register" system will store a callback in the registry
with a specific name to use when trying to get a service.
The getter will throw an error by default if the service
does not exist, except when using the FAIL_GRACEFULLY
constant.
Any service is overwritable by default but can be not using
the $protected = true
register argument.
Constants
FAIL_GRACEFULLY |
Use this constant to NOT throw error when trying to get an unknown service
|
FAIL_WITH_ERROR |
Use this constant to throw error when trying to get an unknown service This is the default behavior. |
Methods
Define a service constructor like array( name , callback , protected )
or a closure
Register a new service called $name
declared as NOT protected by default
Get a service called $name
throwing an error by default if it does not exist yet and can not be created
Test if a service exists in the container
Unset a service if it is not protected
Details
at line 61
mixed
setProvider(
string $name,
array $provider)
Define a service constructor like array( name , callback , protected )
or a closure
at line 71
mixed
setService(
string $name,
object|callable $callback,
bool $protected = false)
Register a new service called $name
declared as NOT protected by default
at line 81
mixed
getService(
string $name,
array $arguments = array(),
int $failure = self::FAIL_WITH_ERROR)
Get a service called $name
throwing an error by default if it does not exist yet and can not be created
at line 89
mixed
hasService(
string $name)
Test if a service exists in the container
at line 97
mixed
unsetService(
string $name)
Unset a service if it is not protected