for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of vaibhavpandeyvpz/pimple-config package.
*
* (c) Vaibhav Pandey <[email protected]>
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.md.
*/
namespace Pimple\Config;
use InvalidArgumentException;
use RuntimeException;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* Class ConfigServiceProvider
* @package Pimple\Config
class ConfigServiceProvider implements ServiceProviderInterface
{
* @inheritdoc
public function register(Container $pimple)
$pimple['config.files'] = function ($pimple) {
return [$pimple['config.file']];
};
$pimple['config.hydrate'] = $pimple->protect(function ($pimple) {
foreach ($pimple['config.files'] as $file) {
if (is_file($file) && is_readable($file)) {
/** @noinspection PhpIncludeInspection */
$values = require $file;
if (is_array($values)) {
foreach ($values as $key => $value) {
$pimple[$key] = $value;
}
} else {
throw new InvalidArgumentException("Configuration file must return an array");
throw new RuntimeException("Could not find or read from {$file}");
});