Service Providers
Apiato service providers are just Laravel Service Providers, and they function in the exact same way as Laravel service providers. However, they come with additional rules and conventions specific to Apiato.
To generate new service providers,
you may use the apiato:make:provider interactive command:
php artisan apiato:make:provider
Rules
- You MUST NOT register any Service Provider in the
config/app.php(except Laravel default service providers). - Each Container:
- MAY have one or many Service Providers.
- All container-specific Service Providers:
- MUST be placed in the
app/Containers/{Section}/{Container}/Providersdirectory.
- MUST be placed in the
- All general Service Providers:
- MUST be placed in the
app/Ship/Providersdirectory.
- MUST be placed in the
- All Service Providers:
- MUST extend the
App\Ship\Parents\Providers\ServiceProviderclass. - The parent extension SHOULD be aliased as
ParentServiceProvider.
- MUST extend the
- When using Laravel built-in Service Providers:
EventServiceProviderMUST extendApp\Ship\Parents\Providers\EventServiceProvider.RouteServiceProviderMUST extendApp\Ship\Parents\Providers\RouteServiceProvider.- The parent extension SHOULD be aliased as
Parent{ServiceProviderName}. For example:ParentAuthServiceProvider.
Folder Structure
app
├── Containers
│ └── Section
│ └── Container
│ └── Providers
│ ├── EventServiceProvider.php
│ ├── ServiceProvider.php
│ ├── CustomServiceProvider.php
│ └── ...
└── Ship
└── Providers
├── ShipServiceProvider.php
├── CustomServiceProvider.php
└── ...
Code Example
Service Providers are defined exactly as you would define them in Laravel.
Service Providers Registration
Normally, service providers are registered in the bootstrap/providers.php file.
However, Apiato is configured
to load all service provider files in the app/Containers/{Section}/{Container}/Providers and app/Ship/Providers directories.
This means you don't need to manually register them in the bootstrap/providers.php file.
If the default configuration does not suit your needs, you can customize it via the Apiato Configuration class.
Third-Party Service Providers
When dealing with third-party packages that require service provider registration in bootstrap/providers.php file,
you should follow these guidelines:
-
Specific Container Usage: If the package is used within a particular container, register its service provider in that container
App\Containers\{Section}\{Container}\Providers\ServiceProviderclass. -
Framework-wide Usage: If the package is generic and used throughout the entire application, you can register its service provider in the
App\Ship\Prviders\ShipServiceProviderclass. However, avoid registering it directly inconfig/app.php.