class ApiServiceContainer extends ServiceContainer

A service container with constructors based on an API declaration and validation

Traits

Patterns\Traits\ApiManagerTrait
Patterns\Traits\SingletonTrait

Methods

$this
init( array $initial_services = array(), array $services_providers = array(), array $services_protected = array())

Initialize the service container system

mixed
setProvider( string $name, array $provider)

Define a service constructor like array( name , callback , protected ) or a closure

mixed
getProvider( string $name)

Get a service constructor if it exists

bool
hasProvider( string $name)

Test if a constructor exists for a service

$this
setProtected( string $name)

Define a service as protected

bool
isProtected( string $name)

Test if a service is protected

mixed
setService( string $name, object|callable $callback, bool $protected = false)

Register a new service called $name declared as NOT protected by default

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

mixed
hasService( string $name)

Test if a service exists in the container

mixed
unsetService( string $name)

Unset a service if it is not protected

static  object
apiFactory( string $name, string $class, array $arguments = array())

Usage:

Details

in ServiceContainer at line 75
$this init( array $initial_services = array(), array $services_providers = array(), array $services_protected = array())

Initialize the service container system

Parameters

array $initial_services
array $services_providers
array $services_protected

Return Value

$this

in ServiceContainer at line 113
mixed setProvider( string $name, array $provider)

Define a service constructor like array( name , callback , protected ) or a closure

Parameters

string $name
array $provider A service array constructor like array( name , callback , protected ) callable $provider A callback as a closure that must return the service object: function ($name, $arguments) {} ServiceProviderInterface $provider A \ServiceContainer\ServiceProviderInterface instance

Return Value

mixed

in ServiceContainer at line 128
mixed getProvider( string $name)

Get a service constructor if it exists

Parameters

string $name

Return Value

mixed

in ServiceContainer at line 140
bool hasProvider( string $name)

Test if a constructor exists for a service

Parameters

string $name

Return Value

bool

in ServiceContainer at line 151
$this setProtected( string $name)

Define a service as protected

Parameters

string $name

Return Value

$this

in ServiceContainer at line 163
bool isProtected( string $name)

Test if a service is protected

Parameters

string $name

Return Value

bool

in ServiceContainer at line 180
mixed setService( string $name, object|callable $callback, bool $protected = false)

Register a new service called $name declared as NOT protected by default

Parameters

string $name
object|callable $callback
bool $protected

Return Value

mixed

Exceptions

ErrorException

in ServiceContainer at line 205
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

Parameters

string $name
array $arguments
int $failure

Return Value

mixed

Exceptions

ErrorException

in ServiceContainer at line 229
mixed hasService( string $name)

Test if a service exists in the container

Parameters

string $name

Return Value

mixed

in ServiceContainer at line 241
mixed unsetService( string $name)

Unset a service if it is not protected

Parameters

string $name

Return Value

mixed

Exceptions

ErrorException

at line 56
static object apiFactory( string $name, string $class, array $arguments = array())

Usage:

self::set($var, self::apiFactory($var, $val));

Parameters

string $name
string $class
array $arguments

Return Value

object

Exceptions

ErrorException