PHP code example of league / config
1. Go to this page and download the library: Download league/config library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
league / config example snippets
use League\Config\Configuration;
use Nette\Schema\Expect;
// Define your configuration schema
$config = new Configuration([
'database' => Expect::structure([
'driver' => Expect::anyOf('mysql', 'postgresql', 'sqlite')->ng()->ead"),
'path' => Expect::string()->assert(function ($path) { return \is_writeable($path); })->p.log');
// You can now retrieve those values with `get()`.
// Validation and defaults will be applied for you automatically
$config->get('database'); // Fetches the entire "database" section as an array
$config->get('database.driver'); // Fetch a specific nested value with dot notation
$config->get('database/driver'); // Fetch a specific nested value with slash notation
$config->get('database.host'); // Returns the default value "localhost"
$config->get('logging.path'); // Guaranteed to be writeable thanks to the assertion in the schema
// If validation fails an `InvalidConfigurationException` will be thrown:
$config->set('database.driver', 'mongodb');
$config->get('database.driver'); // InvalidConfigurationException
// Attempting to fetch a non-existent key will result in an `InvalidConfigurationException`
$config->get('foo.bar');
// You could avoid this by checking whether that item exists:
$config->exists('foo.bar'); // Returns `false`