league/config
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
dflydev/dot-access-data | v3.0.2 | 10.25 kB | MIT | prod | |
nette/schema | v1.3.0 | - | (BSD-3-Clause OR GPL-2.0-only OR GPL-3.0-only) | prod | 2 |
League/Config is a comprehensive library in PHP that aids you in defining robust configurations for your applications. With this tool, you can specify configuration arrays with rigorous schemas, which ensures your configurations are error-free and standards-compliant. In addition, league/config supports nested configuration arrays, thereby providing a hierarchical arrangement of your settings. This can enhance the readability and maintainability of your configuration files. Furthermore, the library enables access to configuration values using dot notation, which can simplify the retrieval process.
The use of League/Config is quite straightforward. To begin, you'll need PHP 7.4 or higher and Composer installed on your system. You can then install it via Composer using the command composer require league/config
.
With the library installed, you can define your configuration schema using the Configuration
class. You can set the values using the merge()
or set()
methods. After the configurations are set, you can retrieve the values using the get()
method. Here is a simple example code:
use League\Config\Configuration;
use Nette\Schema\Expect;
$config = new Configuration([
'database' => Expect::structure([...]),
'logging' => Expect::structure([...]),
]);
$config->merge([...]);
$config->set('logging.path', '/var/log/myapp.log');
$config->get('database');
$config->get('database.driver');
$this->config->get('database.host');
$config->get('logging.path');
In the example above, Expect::structure([...])
is used to define what each configuration entry should include. Note that validation and default values will be automatically applied when you retrieve the values.
The League/Config official documentation is a great resource to get more in-depth knowledge on using the library, including detailed usage examples, schemas, methods, and background philosophy. It provides a clear explanation of the features and functionality of the library. You can access the full documentation at config.thephpleague.com.