How to use - Nucleus-Framework/configuration GitHub Wiki
Creating a configuration reader
To get started, instantiate the Reader
object and specify the format of the configurations you wish to read. Currently, the supported formats are yaml
and `.env, but you can also create a custom adapter to suit your needs.
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use NucleusFramework\Configuration\Reader;
use NucleusFramework\Configuration\Adapters\DotEnv;
$reader = new Reader(new DotEnv());
$reader->readFromFile(__DIR__ . '/path/to/.env');
Available Methods
get(string $key): string|array
This method allows you to access a specific configuration.
<?php
// ...
$host = $reader->get('DB_HOST');
Note: If the requested configuration does not exist, a RuntimeException will be thrown.
collectAll(): array
Use this method to retrieve all available configurations.
<?php
// ...
$configurations = $reader->collectAll();
Note: The return value may be an empty list if no configurations are available.