Creating and Registering Services¶
The App
class is a container that supports registering new services through the addService
method. You can create your own service by implementing the ServiceInterface
interface.
Services are lazily loaded, which means they'll only be loaded when requested from within the application.
A load
method will be called the first time that service is requested.
Built-in Services:
- Config (registered as
config
) - CommandRegistry (registered as
commandRegistry
) - OutputHandler (registered as
printer
)
Registering a service manually (deprecated - Use method below)¶
PHP | |
---|---|
Registering a service with config files¶
You can register a service by adding a new entry to the services
section of the config/services.php
file.
This file already comes in our official templates.
Using Registered Services¶
The services will be available from controllers via magic __get
method: