Configure the Container
Foundation adapts DI52 behind its container contract. Construct one adapter during application bootstrap and use that instance for every provider.
Create the shared container
Section titled “Create the shared container”Construct the adapter in the application’s composition root. For example, a root bootstrap.php can create and configure the shared instance. Feature classes should receive the services they need rather than creating another container.
Binding the Foundation Container contract allows application services to request the shared adapter. The Dot binding makes the application’s configuration available to every Foundation provider.
Map environment values in config.php
Section titled “Map environment values in config.php”Keep environment access at the configuration boundary rather than reading $_ENV throughout application services. Map values in the root config.php:
Providers read nested values through their inherited $this->config property:
Pass resolved configuration into service constructors through container bindings. Application services should not read the environment or the Dot configuration object directly.
Load an optional .env file
Section titled “Load an optional .env file”The container package includes vlucas/phpdotenv. A non-WordPress application can load a local environment file before requiring config.php:
WordPress applications can map deployment values into $_ENV before the plugin constructs its container. Keep local environment files out of production archives.
Continue
Section titled “Continue”Bootstrap a WordPress plugin with one application object that owns the container, configuration, and provider order.