40 lines
798 B
PHP
40 lines
798 B
PHP
<?php
|
|
|
|
namespace Deblan;
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
class ConfigLoader
|
|
{
|
|
protected $configFile;
|
|
|
|
protected $filesystem;
|
|
|
|
public function __construct($configFile = 'app/config.yml')
|
|
{
|
|
$this->configFile = $configFile;
|
|
$this->filesystem = new Filesystem();
|
|
}
|
|
|
|
public function configExists()
|
|
{
|
|
return $this->filesystem->exists($this->configFile);
|
|
}
|
|
|
|
public function save(array $data)
|
|
{
|
|
$config = array_merge(
|
|
$this->getConfig(),
|
|
$data
|
|
);
|
|
|
|
$this->filesystem->dumpFile($this->configFile, Yaml::dump($config));
|
|
}
|
|
|
|
public function getConfig()
|
|
{
|
|
return $this->configExists() ? Yaml::parse($this->configFile) : [];
|
|
}
|
|
}
|