tereta / config
Requires
- php: >=8.4
- tereta/application: ^1.0
- tereta/core: ^1.0
- tereta/db: ^1.0
Suggests
- tereta/logger: Enables error logging when DB-backed configuration loading fails.
README
๐ ะ ัััะบะธะน | English
Installation
composer require tereta/config
Configuration layers
Values are resolved as a cascade, in priority order:
- In-memory layer โ values set from PHP code via
Pool::set(). - Site-specific DB layer โ rows from the
configtable withsite_id = {id}(only whenget()is called with a$siteId). - Global DB layer โ rows from the
configtable withsite_id IS NULL.
DB rows are loaded lazily on the first get() call and cached in memory for the lifetime of the singleton.
In-memory layer
Values set directly from PHP code. Stored in memory on top of Tereta\Core\Data\Value and support dot-notation paths.
use Tereta\Config\Services\Pool;
Pool::singleton()->set('site.name', 'My Site');
Pool::singleton()->set(
'site',
['name' => 'My Site']
);
$value = Pool::singleton()->get('site.name');
Note: programmatic
set()calls should run during bootstrap โ before the firstget(). After the DB layers are first loaded, subsequentset()calls are not reflected in the read cache.
Reading global DB configuration
Applies to all sites. Rows in the config table with site_id IS NULL.
use Tereta\Config\Services\Pool;
$value = Pool::singleton()->get('store.name');
Reading site-specific configuration
Returns the value for the given site; falls back to the global value when no site override exists.
use Tereta\Config\Services\Pool;
$value = Pool::singleton()->get('store.name', $siteId);
config table schema
| Field | Type | Purpose |
|---|---|---|
id | integer (PK) | Auto-increment |
identifier | varchar(127) | Configuration key (supports dot-notation) |
value | text | Value |
site_id | integer (FK) | NULL for global, otherwise references site |
Rows in the config table are created by external tooling (migrations, admin UI). This module exposes read-only access via Pool::get().