Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
API Reference
The full surface of the package's public types. Behavioural deep-dives are linked into the relevant guides.
Namespace: InitPHP\Config (interfaces under InitPHP\Config\Interfaces,
exceptions under InitPHP\Config\Exceptions).
| Type | Kind | Summary |
|---|---|---|
ConfigInterface | interface | The shared read/write contract. |
AbstractConfig | abstract class | Shared implementation of the contract. |
Classes | abstract class | Properties-as-configuration base. |
Library | final class | Main object + loader API. |
Config | final class | Static facade over a shared Library. |
ConfigException | class | Thrown by loaders on failure. |
InitPHP\Config\Interfaces\ConfigInterface — the minimal contract every
configuration store fulfils. Depend on this in service signatures.
interface ConfigInterface
{
publicfunctionset(string$key, $value): self;
publicfunctionget(string$key, $default = null);
publicfunctionhas(string$key): bool;
publicfunctionremove(string$key): self;
publicfunctionall(): array;
}| Method | Returns | Description |
|---|---|---|
set(string $key, $value) | static | Write a value; intermediate arrays are created for dotted keys. |
get(string $key, $default = null) | mixed | Read a value, or $default when the key is absent. |
has(string $key) | bool | Whether the key exists (a stored null still counts as present). |
remove(string $key) | static | Remove a key; a no-op when it is absent. |
all() | array | The entire configuration tree as a plain array. |
Keys may use dotted-path notation; see Keys & Dotted Paths.
InitPHP\Config\AbstractConfig — abstract, implements ConfigInterface.
Holds the underlying ParameterBag
and implements the shared CRUD + lifecycle. Concrete subclasses populate
the store in their constructor. You do not use this type directly; it is
the common base for Classes and Library.
abstractclass AbstractConfig implements ConfigInterface
{
protectedParameterBag$parameterBag;
finalprotectedstaticfunctionnewParameterBag(array$data = []): ParameterBag;
publicfunction__destruct();
publicfunctionset(string$key, $value): ConfigInterface;
publicfunctionget(string$key, $default = null);
publicfunctionhas(string$key): bool;
publicfunctionremove(string$key): ConfigInterface;
publicfunctionall(): array;
publicfunctionclose(): void;
}| Member | Description |
|---|---|
newParameterBag(array $data = []) | Builds a store in multi (dotted) + case-insensitive mode. Used by every subclass for consistency. |
close() | Clears the tree by resetting to a fresh empty store; the instance stays usable (options preserved). |
__destruct() | Calls close(). |
InitPHP\Config\Classes — abstract, extends AbstractConfig.
Turns a subclass's own properties into a configuration tree. See
Configuration Classes.
abstractclass Classes extends AbstractConfig
{
publicfunction__construct();
}- Imports the default values of the subclass's public and protected properties (private properties are excluded).
- The internal
parameterBagproperty is never imported. - Provides the full
ConfigInterfacesurface inherited fromAbstractConfig.
finalclass AppConfig extends Classes
{
publicstring$url = 'http://lvh.me';
publicarray$db = ['host' => 'localhost'];
}
$config = newAppConfig();
$config->get('db.host'); // 'localhost'InitPHP\Config\Library — final, extends AbstractConfig.
The main entry point: the CRUD surface plus loaders and object access.
See The Library Object.
finalclass Library extends AbstractConfig
{
publicconstVERSION = '2.0.0';
publicfunction__construct(array$data = []);
publicfunction__get(string$name); // object-style readpublicfunction__debugInfo(): array;
publicfunctionversion(): string;
publicfunctionreplace(array$data): self;
publicfunctionsetArray(?string$name, array$assoc = []): self;
publicfunctionsetFile(?string$name, string$path): self;
publicfunctionsetDir(?string$name, string$path, array$exclude = []): self;
publicfunctionsetClass($classOrObject): self; // string|object
}publicfunction __construct(array$data = []);Seeds the store with $data in dotted-path, case-insensitive mode.
publicfunction version(): string;Returns the package version string (the VERSION constant, e.g.
'2.0.0').
publicfunction replace(array$data): self;Discards the entire tree and installs $data. Contrast with
set(), which writes a single key.
publicfunction setArray(?string$name, array$assoc = []): self;Imports an associative array under $name, or merges it into the root
when $name is null/''. See Loaders → setArray.
publicfunction setFile(?string$name, string$path): self;Loads a PHP file that returns an array. Throws
ConfigException when the file is missing, lacks a
.php extension, or does not return an array. See
Loaders → setFile.
publicfunction setDir(?string$name, string$path, array$exclude = []): self;Loads every top-level *.php file in $path. $name is an optional
common prefix; $exclude lists base names to skip. Throws
ConfigException when $path is not a directory.
See Loaders → setDir.
publicfunction setClass($classOrObject): self; // accepts string|objectImports the public properties of a class name (defaults) or object
(runtime values) under the class's short name. Throws
ConfigException when a class name does not exist.
See Loaders → setClass.
publicfunction __get(string$name);Reads a top-level entry as a value (scalar) or a recursively built
stdClass (array); returns null for unknown keys. See
Object Access.
publicfunction __debugInfo(): array;Returns ['version' => …, 'data' => …] so var_dump() shows the version
and the current tree rather than internals.
InitPHP\Config\Config — final, static facade over a shared
Library. Cannot be instantiated (private constructor). See
The Config Facade.
finalclass Config
{
publicstaticfunction__callStatic(string$name, array$arguments);
publicstaticfunctionreset(): void;
}| Member | Description |
|---|---|
__callStatic() | Forwards any call to the shared Library instance. |
reset() | Discards the shared instance (a no-op if none exists). |
The forwarded methods are declared as @method annotations for IDE
support:
@method static string version()
@method static mixed get(string $key, $default = null)
@method static Library set(string $key, $value)
@method static bool has(string $key)
@method static Library remove(string $key)
@method static array all()
@method static Library replace(array $data)
@method static Library setArray(?string $name, array $assoc = [])
@method static Library setFile(?string $name, string $path)
@method static Library setDir(?string $name, string $path, array $exclude = [])
@method static Library setClass(string|object $classOrObject)
@method static void close()InitPHP\Config\Exceptions\ConfigException — extends
\RuntimeException. Thrown by the loaders. Each failure mode has a named
constructor. See Exceptions.
class ConfigException extends \RuntimeException
{
publicstaticfunctionfileNotFound(string$path): self;
publicstaticfunctionfileMustReturnArray(string$path): self;
publicstaticfunctionnotAPhpFile(string$path): self;
publicstaticfunctionnotADirectory(string$path): self;
publicstaticfunctiondirectoryNotReadable(string$path): self;
publicstaticfunctionclassNotFound(string$class): self;
}- Quick Start — the everyday API in five minutes.
- Loaders — every loader, with examples and error cases.
- Exceptions — messages and handling patterns.
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