Download the PHP package initphp/config without Composer
On this page you can find all versions of the php package initphp/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download initphp/config
More information about initphp/config
Files in initphp/config
Package config
Short Description Advanced configuration manager for PHP with dotted-path access, file/directory/class loaders and a static facade.
License MIT
Informations about the package config
InitPHP Config
Advanced configuration manager for PHP: a single configuration tree with dotted-path access, case-insensitive keys, and loaders for arrays, PHP files, whole directories and class/object properties — usable either as an injectable object or through a static facade.
Requirements
- PHP 8.1 or higher
- initphp/parameterbag
^2.0
Installation
Key Concepts
- Dotted paths —
db.hostaddresseshostinside thedbarray. Keys can be nested arbitrarily deep. - Case-insensitive keys —
DB.Host,db.hostandDb.HOSTall refer to the same entry. Keys are folded to lower-case internally. - Three entry points that all share the same read/write contract
(
ConfigInterface):Classes— turn a class's public properties into configuration.Library— an injectable object with the full loader API.Config— a static facade over a sharedLibrary.
Quick Start
Configuration classes
Declare your configuration as public properties and read it through the shared API:
The Library object
The Config static facade
Every call is forwarded to a lazily created, process-wide Library
singleton:
Reading and writing
The following methods are available on Classes, Library, and the
Config facade alike:
| Method | Description |
|---|---|
get(string $key, mixed $default = null): mixed |
Read a value, or $default when the key is absent. |
set(string $key, mixed $value): self |
Write a value (intermediate arrays are created as needed). |
has(string $key): bool |
Whether the key exists (a stored null still counts as present). |
remove(string $key): self |
Remove a key (a no-op when it is absent). |
all(): array |
The entire configuration tree as a plain array. |
Loaders (Library / Config)
setArray()
Imports an associative array. When $name is null or '' the array is
merged into the root; otherwise it is stored under $name.
setFile()
Loads a PHP file that returns an associative array.
setDir()
Loads every top-level *.php file in a directory. Each file is stored
under a key derived from its base name; when $name is given it becomes a
common prefix. Files can be skipped via $exclude (with or without the
.php suffix).
setClass()
Imports the public properties of a class or object under the class's short name. A class name imports the property defaults; an instance imports the current values.
Object-style access (Library)
A Library exposes top-level entries as read-only nested objects:
Error handling
Loader failures throw
InitPHP\Config\Exceptions\ConfigException
(a RuntimeException): missing files, files that do not return an array,
invalid directories, and unknown class names.
Documentation
In-depth guides with runnable examples live in docs/.
Testing
Credits
License
Released under the MIT License. Copyright © InitPHP.