-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
Quick answers to questions that come up when adopting the package. If your question is not here, please open an issue — documentation fixes are reviewed eagerly.
A single, uniform API over configuration loaded from arrays, PHP files, directories, and class/object properties — with dotted-path access and case-insensitive keys. Use it for application settings, database/cache config, feature flags, and similar.
initphp/parameterbag is the
low-level nested store. initphp/config is built on top of it and
adds: file/directory/class loaders, a static facade, object-style access,
and a default-on case-insensitive, dotted-path configuration. If you only
need a key/value bag, use ParameterBag directly; if you need to load
configuration from multiple sources, use this package.
| You want… | Use |
|---|---|
| Typed, code-defined config | Classes |
| An injectable object loaded at runtime | Library |
| Global access with no wiring |
Config facade |
They share the same read/write contract, so you can start with one and move to another with minimal changes.
Keys are case-insensitive in this package — they are folded to
lower-case internally. HOST, Host, and host all resolve to the same
entry. See Keys & Dotted Paths.
In v2 a null/empty name merges into the root rather than replacing
the whole tree. If you want to discard everything, call
replace(). (This changed
from v1 — see the Migration Guide.)
The Config facade is a static-only utility with a private
constructor. Use the static methods (Config::get(...)), or inject a
Library when you need an object.
Yes. v1 had an inverted prefix bug that dropped the name. v2 applies the
prefix correctly, so files load under app.<file>. Pass null as the
name if you want no prefix. See the Migration Guide.
setClass() reads public properties only,
because it inspects the target class from the outside. The
Classes base — which inspects itself from
within the hierarchy — imports public and protected properties (but
not private).
Either get('db') to receive the array, or use
object access: $library->db->host.
Use has(). A key whose value is null is still considered present;
get() will return that null rather than your default. See
Keys & Dotted Paths.
Call Config::reset() in your test's setUp() (or tearDown()). It
discards the shared singleton so the next test starts clean. For a
Library, just create a new instance per test —
no global state is involved.
No. The package is a loader and accessor; values flow through unchanged.
Validate at the consumer boundary (e.g. when reading db.port, cast and
range-check it there).
No. Both Library and Classes mutate in place. If you need read-only
config after boot, wrap the instance in your own decorator that exposes
only get/has/all.
It is a process-wide singleton; treat it like any shared global. In a
worker that handles many requests in one process, call Config::reset()
(or reload) between requests if request-specific config must not leak.
Yes — every top-level *.php file. Each must return an array, or the
call throws. Keep non-config PHP out of the directory, or list it in the
$exclude argument. See Loaders → setDir.
initphp/config · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core Concepts
Loading Configuration
Reference
Practical Guides
Migration & Help