|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Configuration\Migration; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Migrations\Configuration\Configuration; |
|
8
|
|
|
use Doctrine\Migrations\Configuration\Exception\FileNotFound; |
|
9
|
|
|
use Doctrine\Migrations\Configuration\Migration\Exception\YamlNotAvailable; |
|
10
|
|
|
use Doctrine\Migrations\Configuration\Migration\Exception\YamlNotValid; |
|
11
|
|
|
use Symfony\Component\Yaml\Exception\ParseException; |
|
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
13
|
|
|
use function assert; |
|
14
|
|
|
use function class_exists; |
|
15
|
|
|
use function file_exists; |
|
16
|
|
|
use function file_get_contents; |
|
17
|
|
|
use function is_array; |
|
18
|
|
|
|
|
19
|
|
|
final class YamlFile extends ConfigurationFile |
|
20
|
|
|
{ |
|
21
|
10 |
|
public function getConfiguration() : Configuration |
|
22
|
|
|
{ |
|
23
|
10 |
|
if (! class_exists(Yaml::class)) { |
|
24
|
|
|
throw YamlNotAvailable::new(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
10 |
|
if (! file_exists($this->file)) { |
|
28
|
1 |
|
throw FileNotFound::new($this->file); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
9 |
|
$content = file_get_contents($this->file); |
|
32
|
|
|
|
|
33
|
9 |
|
assert($content !== false); |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
9 |
|
$config = Yaml::parse($content); |
|
37
|
1 |
|
} catch (ParseException $e) { |
|
38
|
1 |
|
throw YamlNotValid::malformed(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
8 |
|
if (! is_array($config)) { |
|
42
|
|
|
throw YamlNotValid::invalid(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
8 |
|
if (isset($config['migrations_paths'])) { |
|
46
|
3 |
|
$config['migrations_paths'] = $this->getDirectoriesRelativeToFile( |
|
47
|
3 |
|
$config['migrations_paths'], |
|
48
|
3 |
|
$this->file |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
8 |
|
return (new ConfigurationArray($config))->getConfiguration(); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|