Expose Bolt's config variables

This commit is contained in:
Xiao Hu Tai
2018-10-03 11:54:24 +02:00
parent 8e13aaddbc
commit 00a4d93161
2 changed files with 38 additions and 0 deletions
+31
View File
@@ -81,6 +81,37 @@ class Config
return $config;
}
/**
* @return array
*/
public function getParameters() : array
{
$array = $this->data->get('general')->toArray();
return $this->flatten($array);
}
/**
* @param array $array
* @param string $prefix
* @return array
*/
private function flatten(array $array, string $prefix = '') : array
{
$result = [];
foreach($array as $key => $value) {
if (is_integer($key)) {
$result[trim($prefix, '.')][] = $value;
}
elseif(is_array($value)) {
$result = $result + $this->flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix . $key] = $value;
}
}
return $result;
}
/**
* Get a config value, using a path.
*
+7
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Bolt;
use Bolt\Configuration\Config;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
@@ -43,6 +44,12 @@ class Kernel extends BaseKernel
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';
$config = new Config();
foreach ($config->getParameters() as $key => $value) {
$container->setParameter('bolt.' . $key, $value);
}
$container->set('config', $config);
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');