PHP code example of helhum / config-loader
1. Go to this page and download the library: Download helhum/config-loader 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/ */
helhum / config-loader example snippets
$context = 'production';
$confDir = '/path/to/conf';
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\ConfigurationLoader(
[
$configReaderFactory->createReader($confDir . '/default.php'),
$configReaderFactory->createReader($confDir . '/' . $context . '.php'),
$configReaderFactory->createReader('PREFIX', ['type' => 'env']),
$configReaderFactory->createReader($confDir . '/override.php'),
]
);
$config = $configLoader->load();
$context = 'production';
$confDir = '/path/to/conf';
$cacheDir = '/path/to/cache';
$cacheIdentifier = md5($context . filemtime('/path/to/.env'));
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\CachedConfigurationLoader(
$cacheDir,
$cacheIdentifier,
function() use ($confDir, $context, $configReaderFactory) {
return new \Helhum\ConfigLoader\ConfigurationLoader(
[
$configReaderFactory->createReader($confDir . '/default.php'),
$configReaderFactory->createReader($confDir . '/' . $context . '.php'),
$configReaderFactory->createReader('PREFIX', ['type' => 'env']),
$configReaderFactory->createReader($confDir . '/override.php'),
]
);
}
);
$config = $configLoader->load();
$context = 'production';
$confDir = '/path/to/conf';
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\ConfigurationLoader(
[
$configReaderFactory->createReader($confDir . '/config.php'),
],
[
new \Helhum\ConfigLoader\Processor\PlaceholderValue(),
]
);
$config = $configLoader->load();
$context = 'production';
$confDir = '/path/to/conf';
$configReaderFactory = new \Helhum\ConfigLoader\ConfigurationReaderFactory($confDir);
$configLoader = new \Helhum\ConfigLoader\ConfigurationLoader(
[
$configReaderFactory->createRootReader($confDir . '/config.yaml'),
]
);
$config = $configLoader->load();