|
| 1 | +# Introduction |
| 2 | + |
| 3 | +In PHP, the `ConfigProvider` is a class that is part of an application's bootstrap process. |
| 4 | +It returns an array of configuration, settings, or anything else your application needs. |
| 5 | +In Dotkernel, each application module and package contains a `ConfigProvider` that normally returns: |
| 6 | + |
| 7 | +- Dependency injection mappings. |
| 8 | +- Request Handlers. |
| 9 | +- Template file paths. |
| 10 | + |
| 11 | +Here is an example in Dotkernel, which is an approach similar to Laminas/Mezzio: |
| 12 | + |
| 13 | +```php |
| 14 | +class ConfigProvider |
| 15 | +{ |
| 16 | + public function __invoke(): array |
| 17 | + { |
| 18 | + return [ |
| 19 | + 'dependencies' => $this->getDependencies(), |
| 20 | + 'templates' => $this->getTemplates(), |
| 21 | + ]; |
| 22 | + } |
| 23 | + |
| 24 | + public function getDependencies(): array |
| 25 | + { |
| 26 | + return [ |
| 27 | + 'factories' => [ |
| 28 | + Handler\HomepageHandler::class => Handler\HomepageHandlerFactory::class, |
| 29 | + Handler\SearchHandler::class => Handler\SearchHandlerFactory::class, |
| 30 | + ], |
| 31 | + 'invokables' => [ |
| 32 | + Console\GenerateSearchData::class => Console\GenerateSearchData::class, |
| 33 | + ], |
| 34 | + ]; |
| 35 | + } |
| 36 | + |
| 37 | + public function getTemplates(): array |
| 38 | + { |
| 39 | + return [ |
| 40 | + 'app' => [__DIR__ . '/../templates/app'], |
| 41 | + 'error' => [__DIR__ . '/../templates/error'], |
| 42 | + ]; |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +All Dotkernel applications and packages use ConfigProviders: |
| 48 | + |
| 49 | +- [Dotkernel API](https://docs.dotkernel.org/api-documentation/) |
| 50 | +- [Dotkernel Admin](https://docs.dotkernel.org/admin-documentation/) |
| 51 | +- [Dotkernel Frontend](https://docs.dotkernel.org/frontend-documentation/) |
| 52 | +- [Dotkernel Light](https://docs.dotkernel.org/light-documentation/) |
| 53 | +- [Dotkernel Packages](https://docs.dotkernel.org/packages/) |
0 commit comments