Class ServiceProvider
Container ServiceProvider
Service provider bundle related services together helping to organize your application's dependencies. They also help improve performance of applications with many services by allowing service registration to be deferred until services are needed.
Property Summary
-
$container protected
ContainerInterface
-
$identifier protected
string
-
$leagueContainer protected
Container
-
$provides protected
array
Method Summary
-
boot() public
Delegate to the bootstrap() method
-
bootstrap() public
Bootstrap hook for ServiceProviders
-
getContainer() public
Get the container.
-
getIdentifier() public
The id of the service provider uniquely identifies it, so that we can quickly determine if it has already been registered. Defaults to get_class($provider).
-
getLeagueContainer() public
Get the container. This will be removed in favour of getContainer returning Container in next major release.
-
provides() public
Returns a boolean if checking whether this provider provides a specific service or returns an array of provided services if no argument passed.
-
register() public
Call the abstract services() method.
-
services() abstract public
Register the services in a provider.
-
setContainer() public
Set a container
-
setIdentifier() public
Set a custom id for the service provider. This enables registering the same service provider multiple times.
-
setLeagueContainer() public
Set a container. This will be removed in favour of setContainer receiving Container in next major release.
Method Detail
boot() ¶ public
boot(): void
Delegate to the bootstrap() method
This method wraps the league/container function so users only need to use the CakePHP bootstrap() interface.
Returns
void
bootstrap() ¶ public
bootstrap(Cake\Core\ContainerInterface $container): void
Bootstrap hook for ServiceProviders
This hook should be implemented if your service provider needs to register additional service providers, load configuration files or do any other work when the service provider is added to the container.
Parameters
-
Cake\Core\ContainerInterface
$container The container to add services to.
Returns
void
getContainer() ¶ public
getContainer(): Cake\Core\ContainerInterface
Get the container.
This method's actual return type and documented return type differ because PHP 7.2 doesn't support return type narrowing.
Returns
Cake\Core\ContainerInterface
getIdentifier() ¶ public
getIdentifier(): string
The id of the service provider uniquely identifies it, so that we can quickly determine if it has already been registered. Defaults to get_class($provider).
Returns
string
getLeagueContainer() ¶ public
getLeagueContainer(): Container
Get the container. This will be removed in favour of getContainer returning Container in next major release.
Returns
Container
provides() ¶ public
provides(string $service): boolean
Returns a boolean if checking whether this provider provides a specific service or returns an array of provided services if no argument passed.
Parameters
-
string
$service
Returns
boolean
register() ¶ public
register(): void
Call the abstract services() method.
This method primarily exists as a shim between the interface that league/container has and the one we want to offer in CakePHP.
Returns
void
services() ¶ abstract public
services(Cake\Core\ContainerInterface $container): void
Register the services in a provider.
All services registered in this method should also be included in the $provides property so that services can be located.
Parameters
-
Cake\Core\ContainerInterface
$container The container to add services to.
Returns
void
setContainer() ¶ public
setContainer(ContainerInterface $container): self
Set a container
Parameters
-
ContainerInterface
$container
Returns
self
setIdentifier() ¶ public
setIdentifier(string $id): self
Set a custom id for the service provider. This enables registering the same service provider multiple times.
Parameters
-
string
$id
Returns
self
setLeagueContainer() ¶ public
setLeagueContainer(Container $container): self
Set a container. This will be removed in favour of setContainer receiving Container in next major release.
Parameters
-
Container
$container
Returns
self