Skip to content

Extending

The config is designed to be extended. You can add your own config files to the config directory, write providers that act on them, and replace built-in providers when you need different behaviour.

Create a new file in the config directory. Any PHP file there is automatically loaded — the filename (without .php) becomes the top-level config key.

config/foobar.php
<?php
return [
'foo' => 'bar',
];

Read it anywhere with Config::get():

Config::getInstance()->get('foobar.foo'); // 'bar'

A provider is a class responsible for reading config values and acting on them when the theme boots. Every built-in config file has a corresponding provider in app/Lib/Config/Provider/.

To add your own, create a class that implements ProviderContract:

app/Provider/FoobarProvider.php
<?php
namespace App\Provider;
use App\Lib\Config\Config;
use App\Lib\Contracts\ProviderContract;
class FoobarProvider implements ProviderContract
{
public function boot(): void
{
$value = Config::getInstance()->get('foobar.foo');
if ($value === 'bar') {
// do something
}
}
}

Register it in functions.php before calling $config->load():

functions.php
$config = Config::getInstance();
$config->addProvider(new App\Provider\FoobarProvider);
$config->load();

If you need to change how a built-in config file is handled, extend the existing provider and swap it out with replaceProvider().

app/Provider/MyThemeProvider.php
<?php
namespace App\Provider;
use App\Lib\Config\Provider\ThemeProvider;
class MyThemeProvider extends ThemeProvider
{
public function boot(): void
{
parent::boot();
// run additional logic after the default theme setup
}
}
functions.php
$config = Config::getInstance();
$config->replaceProvider(ThemeProvider::class, new App\Provider\MyThemeProvider);
$config->load();

replaceProvider finds the first registered provider that is an instance of the given class and swaps it. If no match is found, the replacement is appended instead.

To completely override a provider without running the original logic, omit the parent::boot() call.