mirror of
https://github.com/jbcr/core.git
synced 2026-04-23 16:48:17 +02:00
Expose Bolt's config variables
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user