1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
<?php
namespace Inlm\SchemaGenerator\Adapters;
use Inlm\SchemaGenerator\IAdapter;
use Inlm\SchemaGenerator\Configuration;
use Inlm\SchemaGenerator\ConfigurationFactory;
use Inlm\SchemaGenerator\ConfigurationSerializer;
use Nette\Utils\FileSystem;
use Nette\Neon\Neon;
class NeonAdapter implements IAdapter
{
private $file;
public function __construct($file)
{
$this->file = $file;
}
public function load()
{
$config = array();
if (file_exists($this->file)) {
$content = FileSystem::read($this->file);
if ($content !== '') {
$config = Neon::decode($content);
}
}
return ConfigurationFactory::fromArray($config);
}
public function save(Configuration $configuration)
{
$content = Neon::encode(ConfigurationSerializer::serialize($configuration), Neon::BLOCK);
FileSystem::write($this->file, "# DON'T EDIT THIS FILE!\n\n" . rtrim($content) . "\n", NULL);
}
}