t411-console/src/Api/ConfigLoader.php

39 lines
750 B
PHP
Raw Normal View History

2015-02-10 01:17:29 +01:00
<?php
namespace Api;
use Symfony\Component\Filesystem\Filesystem;
2015-02-10 02:05:21 +01:00
use Symfony\Component\Yaml\Yaml;
2015-02-10 01:17:29 +01:00
class ConfigLoader
{
protected $configFile = 'app/config.yml';
protected $filesystem = null;
2015-02-10 02:05:21 +01:00
public function __construct()
2015-02-10 01:17:29 +01:00
{
$this->filesystem = new Filesystem();
}
public function configExists()
{
return $this->filesystem->exists($this->configFile);
}
2015-02-10 02:05:21 +01:00
public function save(array $data)
{
$config = array_merge(
$this->getConfig(),
$data
);
$this->filesystem->dumpFile($this->configFile, Yaml::dump($config));
}
public function getConfig()
{
2015-02-10 14:09:40 +01:00
return $this->configExists() ? Yaml::parse($this->configFile) : [];
2015-02-10 02:05:21 +01:00
}
2015-02-10 01:17:29 +01:00
}