PHP code example of germania-kg / configreader

1. Go to this page and download the library: Download germania-kg/configreader 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/ */

    

germania-kg / configreader example snippets



namespace Germania\ConfigReader;

interface ConfigReaderInterface
{
    public function __invoke( ... $files );
}


use Germania\ConfigReader\YamlConfigReader;

$reader = new YamlConfigReader( "/path/to/configs");

// Returns array
$config = $reader("defaults.yaml", "optionals.yaml");


use Germania\ConfigReader\YamlConfigReader;
use Germania\ConfigReader\CacheConfigReader;

$reader = new YamlConfigReader( "/path/to/configs");
$cache_item_pool = ... // PSR-6 CacheItemPool
$cache_lifetime = 3600;
$logger = ...
  
$cache_reader = new CacheConfigReader($reader, $cache_item_pool, $cache_lifetime);
$cache_reader = new CacheConfigReader($reader, $cache_item_pool, $cache_lifetime, $logger);

$config = $cache_reader("defaults.yaml", "optionals.yaml");


use use Symfony\Component\Yaml\Yaml;

$reader = new YamlConfigReader( "/path/to/configs");
$reader->setYamlFlags( Yaml::PARSE_DATETIME | Yaml::PARSE_CONSTANT );

$reader = new YamlConfigReader( "/path/to/configs");
$reader->setIgnoreKey( "_ignore" );
$config = $reader("ignoring.yaml");

# Will both be FALSE:
isset( $config["_ignore"])
isset( $config["foo"])

# Reset again
$reader->setIgnoreKey( null );

use Germania\ConfigReader\ConfigReaderExceptionInterface;
try {
	$config = $reader("defaults.yaml", "optionals.yaml");  
}
catch (ConfigReaderExceptionInterface $e)
{
  echo $e->getMessage();
}