decodelabs / dovetail
Comprehensive config solution
Installs: 1 502
Dependents: 6
Suggesters: 1
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- decodelabs/archetype: ^0.3
- decodelabs/atlas: ^0.12
- decodelabs/coercion: ^0.2.7
- decodelabs/collections: ^0.9
- decodelabs/exceptional: ^0.4.4
- decodelabs/fluidity: ^0.3.4
- decodelabs/lucid: ^0.4.7
- decodelabs/veneer: ^0.11.6
- vlucas/phpdotenv: ^5.5
Requires (Dev)
- decodelabs/genesis: ^0.9
- decodelabs/phpstan-decodelabs: ^0.6.6
README
Comprehensive config solution for PHP
Dovetail provides a simple, flexible and powerful way to manage configuration data in PHP applications.
Get news and updates on the DecodeLabs blog.
Installation
Install via Composer:
composer require decodelabs/dovetail
Usage
Importing
Dovetail uses Veneer to provide a unified frontage under DecodeLabs\Dovetail
.
You can access all the primary functionality via this static frontage without compromising testing and dependency injection.
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 Env facade.
use DecodeLabs\Dovetail; $dbHost = Dovetail::envString('DB_HOST', 'localhost'); // String $dbPort = Dovetail::envInt('DB_PORT', 3306); // Int $debug = Dovetail::envBool('DEBUG', false); // Bool $test = Dovetail::env('TEST', 'default'); // Mixed
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 Dovetail::env*()
methods or $_ENV
to inject these values into your config.
# config/database.php use DecodeLabs\Dovetail; return [ 'adapter' => 'mysql', 'host' => $_ENV['DB_HOST'] ?? 'localhost', // or 'port' => Dovetail::envInt('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; $config = Dovetail::load('database'); $adapter = $config->getAdapter(); // 'mysql'
Licensing
Dovetail is licensed under the proprietary License. See LICENSE for the full license text.