Configula v4 introduces PHP8 support, and while there was an attempt to keep breaking changes to a minimum, there are a few to address:
If you sub-class ConfigValues
and have custom logic in the __construct()
method, you'll need to move that logic into
the new init()
method. The ConfigValues::__construct()
is now declared final.
The *Loader
classes are all final now, with the exception of AbstractFileLoader
. If you extend any of them, you may
need to refactor to use a composition-style rather than inheritance-style design pattern (e.g. decorator, etc.)
Configula v3 is quite different from v2. But, you can replicate the behavior of Configula v2 with minimal code changes as follows:
Configula\Config
has now become Configula\ConfigValues
. Update all references.
Before upgrade:
use Configula\Config;
$config = new Config('/path/to/config/files', ['default' => 'values']);
After upgrade:
use Configula\ConfigFactory;
$config = ConfigFactory::loadPath('/path/to/config/files', ['default' => 'values']);
One behavior change in v3 is that loadPath()
will now recursively load configuration files from your configuration
path. If you want to read configuration files only from the top-level directory of your config path, you can do the
following:
use Configula\ConfigFactory;
$config = ConfigFactory::loadSingleDirectory('/path/to/config/files', ['default' => 'values']);
Before upgrade:
$config->loadConfig('/some/path');
After upgrade:
// Note that the ConfigValues class is now immutable, so you need to use the instance that
// is returned from the merge method.
$config = $config->merge((new DecidingFileLoader('/some/path')->load()));
Before upgrade:
$config->getItem('some_item', 'default');
After upgrade:
// same behavior as v2 getItem()
$config->get('some_item', 'default');
// returns NULL
$config->find('non_existent_item');
// throws exception
$config->get('non_existent_item');
Before upgrade:
$config->valid('some_item');
After upgrade:
$config->has('some_item');
Before upgrade:
$config->getItems();
After upgrade:
$config->getArrayCopy();