gacela-project / gacela-env-config-reader
Load .env files into Gacela
0.3
2024-06-28 18:52 UTC
Requires
- php: >=8.0
- gacela-project/gacela: >=1.7
- symfony/dotenv: ^v6.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.18
- symfony/var-dumper: ^5.4
- vimeo/psalm: ^5.25
README
Load .env configuration files for your Gacela projects.
composer require gacela-project/gacela-env-config-reader
Setup
You can define the reader configuration either in the Gacela::bootstrap()
or in a gacela.php
file.
Option A)
Define the configuration in a gacela.php
file in the root of your project (recommended way):
<?php # gacela.php use Gacela\Framework\Bootstrap\GacelaConfig; use Gacela\Framework\Config\ConfigReader\EnvConfigReader; return static function (GacelaConfig $config): void { $config->addAppConfig('config/.env*', 'config/.env.local.dist', EnvConfigReader::class); };
Option B)
Define all configuration on the fly in the bootstrap itself.
<?php # public/index.php use Gacela\Framework\Bootstrap\GacelaConfig; use Gacela\Framework\Config\ConfigReader\EnvConfigReader; use Gacela\Framework\Gacela; $config = static function (GacelaConfig $config): void { $config->addAppConfig('config/.env*', 'config/.env.local.dist', EnvConfigReader::class); }; Gacela::bootstrap($appRootDir, $config);
You can define more than one ConfigReader
at once.
$config = static function (GacelaConfig $config): void { $config->addAppConfig('config/.env*', 'config/.env.local.dist', EnvConfigReader::class); $config->addAppConfig('config/*.php', 'config/local.php'); $config->addAppConfig('config/*.custom', '', CustomConfigReader::class); }