-
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
{
public function set(string $key, $value): self;
public function get(string $key, $default = null);
public function has(string $key): bool;
public function remove(string $key): self;
public function all(): 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.
abstract class AbstractConfig implements ConfigInterface
{
protected ParameterBag $parameterBag;
final protected static function newParameterBag(array $data = []): ParameterBag;
public function __destruct();
public function set(string $key, $value): ConfigInterface;
public function get(string $key, $default = null);
public function has(string $key): bool;
public function remove(string $key): ConfigInterface;
public function all(): array;
public function close(): 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.
abstract class Classes extends AbstractConfig
{
public function __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.
final class AppConfig extends Classes
{
public string $url = 'http://lvh.me';
public array $db = ['host' => 'localhost'];
}
$config = new AppConfig();
$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.
final class Library extends AbstractConfig
{
public const VERSION = '2.0.0';
public function __construct(array $data = []);
public function __get(string $name); // object-style read
public function __debugInfo(): array;
public function version(): string;
public function replace(array $data): self;
public function setArray(?string $name, array $assoc = []): self;
public function setFile(?string $name, string $path): self;
public function setDir(?string $name, string $path, array $exclude = []): self;
public function setClass($classOrObject): self; // string|object
}public function __construct(array $data = []);Seeds the store with $data in dotted-path, case-insensitive mode.
public function version(): string;Returns the package version string (the VERSION constant, e.g.
'2.0.0').
public function replace(array $data): self;Discards the entire tree and installs $data. Contrast with
set(), which writes a single key.
public function 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.
public function 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.
public function 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.
public function 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.
public function __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.
public function __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.
final class Config
{
public static function __callStatic(string $name, array $arguments);
public static function reset(): 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
{
public static function fileNotFound(string $path): self;
public static function fileMustReturnArray(string $path): self;
public static function notAPhpFile(string $path): self;
public static function notADirectory(string $path): self;
public static function directoryNotReadable(string $path): self;
public static function classNotFound(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