Search by

denosyscore / config

deondazy

Configuration repository with correct dot paths, typed reads and typed sections, plus one environment reader

Package info

github.com/denosyscore/config

pkg:composer/denosyscore/config

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.22.0 2026-11-13 14:02 UTC

This package is auto-updated.

Last update: 2026-11-13 14:04:41 UTC


README

Read-only split. This package is developed in denosyscore/framework under packages/config. Open issues and pull requests there.

Configuration read by dot path, with typed reads, typed sections and one environment reader. It has no framework dependency.

Installation

composer require denosyscore/config

Quick start

A stored null is a value: get() returns it rather than the default, and has() reports it. Typed readers throw a ConfigException that names the path when a value is missing or has the wrong type.

<?php

require __DIR__ . '/vendor/autoload.php';

use Denosys\Config\ConfigSection;
use Denosys\Config\Repository;

$config = new Repository([
    'app' => ['name' => 'Shop', 'debug' => null, 'port' => 8080],
    'mail' => ['from' => ['address' => 'shop@example.test', 'name' => 'Shop']],
]);

var_dump($config->get('app.debug', true));  // NULL: the stored value, not the default
var_dump($config->has('app.debug'));        // bool(true)
echo $config->int('app.port'), "\n";        // 8080

final readonly class MailFrom implements ConfigSection
{
    public function __construct(public string $address, public string $name) {}

    public static function from(Repository $config): static
    {
        return new static($config->string('mail.from.address'), $config->string('mail.from.name'));
    }
}

echo $config->section(MailFrom::class)->address, "\n";  // shop@example.test

Loading files

ConfigLoader::fromDirectory() loads every <name>.php file that returns an array, under <name>. writeCache() compiles the result to one PHP file, written atomically, and fromCache() reads it back.

Environment

Environment is the one way to read environment variables. It loads dotenv files without overwriting variables already set, and casts values one way everywhere: true, false, null and empty (optionally in parentheses), (int)42, (float)1.5; anything else stays a string.