定制 decodelabs/dovetail 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

decodelabs/dovetail

最新稳定版本:v0.3.6

Composer 安装命令:

composer require decodelabs/dovetail

包简介

Comprehensive config solution

README 文档

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

This package requires PHP 8.4 or higher.

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.

统计信息

  • 总下载量: 6.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 6
  • 推荐数: 2

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-17