InitPHP\Config\Classes is an abstract base class
that turns a subclass's properties into a configuration tree. It is the
most natural fit for configuration that ships with your application as
code.
use InitPHP\Config\Classes;
final class AppConfig extends Classes
{
public string $url = 'http://lvh.me';
public string $name = 'LocalHost';
/** @var array<string, string> */
public array $db = [
'host' => 'localhost',
'user' => 'root',
];
}$config = new AppConfig();
$config->get('url'); // "http://lvh.me"
$config->get('name'); // "LocalHost"
$config->get('db.host'); // "localhost" (nested array → dotted path)
$config->get('db.user'); // "root"
$config->has('URL'); // true (case-insensitive)
$config->all(); // ['url' => ..., 'name' => ..., 'db' => [...]]A config class is not frozen — you can set and remove after
construction:
$config->set('db.pass', 'secret');
$config->get('db.pass'); // "secret"
$config->remove('db.pass');
$config->has('db.pass'); // false- The property default values declared on the class are imported.
- Both public and protected properties are included (they are visible
from the
Classesbase in the inheritance chain); private properties of the subclass are not. - The internal
parameterBaginfrastructure property is never part of the tree.
$config->has('parameterBag'); // falseNote: this differs from
Library::setClass(), which imports public properties only. The difference is intentional:Classesinspects itself from within the hierarchy, whereassetClass()inspects an unrelated class from the outside.