The start of something beautiful

This commit is contained in:
2024-09-11 22:48:07 -06:00
parent 45acea47f3
commit f5997ee5ec
5614 changed files with 630696 additions and 0 deletions
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Doctrine\Migrations\Configuration\Migration;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\Exception\FileNotFound;
use Doctrine\Migrations\Configuration\Migration\Exception\JsonNotValid;
use function assert;
use function file_exists;
use function file_get_contents;
use function json_decode;
use function json_last_error;
use const JSON_ERROR_NONE;
final class JsonFile extends ConfigurationFile
{
public function getConfiguration(): Configuration
{
if (! file_exists($this->file)) {
throw FileNotFound::new($this->file);
}
$contents = file_get_contents($this->file);
assert($contents !== false);
$config = json_decode($contents, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw JsonNotValid::new();
}
if (isset($config['migrations_paths'])) {
$config['migrations_paths'] = $this->getDirectoriesRelativeToFile(
$config['migrations_paths'],
$this->file,
);
}
return (new ConfigurationArray($config))->getConfiguration();
}
}