decodelabs/dovetail

Comprehensive config solution

v0.3.1 2025-08-21 20:05 UTC

README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

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.