decodelabs / dovetail
Comprehensive config solution
Installs: 4 029
Dependents: 7
Suggesters: 2
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.4
- decodelabs/archetype: ^0.4
- decodelabs/atlas: ^0.14
- decodelabs/coercion: ^0.3.5
- decodelabs/collections: ^0.12
- decodelabs/exceptional: ^0.6.3
- decodelabs/fluidity: ^0.3.7
- decodelabs/iota: ^0.3
- decodelabs/kingdom: ^0.1
- decodelabs/lucid: ^0.6
- decodelabs/monarch: ^0.2
- vlucas/phpdotenv: ^5.6.2
Requires (Dev)
- decodelabs/genesis: ^0.13
- decodelabs/phpstan-decodelabs: ^0.7
Conflicts
- decodelabs/genesis: <0.13
README
Comprehensive config solution for PHP
Dovetail provides a simple, flexible and powerful way to manage configuration data in PHP applications.
Installation
Install via Composer:
composer require decodelabs/dovetail
Usage
Env
Dovetail utilises vlucas/phpdotenv to load environment variables from a .env
file in your project root. This is automatically loaded when you first access the Dovetail service.
use DecodeLabs\Dovetail\Env; $dbHost = Env::asString('DB_HOST', 'localhost'); // String $dbPort = Env::asInt('DB_PORT', 3306); // Int $debug = Env::asBool('DEBUG', false); // Bool $test = Env::asString('TEST', 'default'); // Mixed
Use Env::try*()
methods to avoid throwing exceptions when the environment variable is not set and no default value is provided.
Config
Dovetail provides structures to allow loading config files from any custom location, into Repository
container tree objects, and presented in domain specific Config
objects which can then provide custom data access methods according to your needs.
Sensitive data should be loaded from a .env
file and not stored in config files - use the Env::as*()
and Env::try*()
methods to inject these values into your config.
# config/database.php use DecodeLabs\Dovetail\Env; return [ 'adapter' => 'mysql', 'host' => Env::asString('DB_HOST', 'localhost'), 'port' => Env::asInt('DB_PORT', 3306), ];
# app/Config/Database.php use DecodeLabs\Dovetail\Config; use DecodeLabs\Dovetail\ConfigTrait; class Database implements Config { use ConfigTrait; public function getAdapter(): string { return $this->data['adapter'] ?? 'mysql'; } public function getHost(): string { return $this->data['host'] ?? 'localhost'; } public function getPort(): int { return $this->data['port'] ?? 3306; } }
use DecodeLabs\Dovetail; use DecodeLabs\Monarch; $dovetail = Monarch::getService(Dovetail::class); $config = $dovetail->load('database'); $adapter = $config->getAdapter(); // 'mysql'
Licensing
Dovetail is licensed under the proprietary License. See LICENSE for the full license text.