1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Configuration; |
6
|
|
|
|
7
|
|
|
use Doctrine\Migrations\Configuration\Exception\XmlNotValid; |
8
|
|
|
use DOMDocument; |
9
|
|
|
use const DIRECTORY_SEPARATOR; |
10
|
|
|
use const LIBXML_NOCDATA; |
11
|
|
|
use function libxml_clear_errors; |
12
|
|
|
use function libxml_use_internal_errors; |
13
|
|
|
use function simplexml_load_file; |
14
|
|
|
|
15
|
|
|
class XmlConfiguration extends AbstractFileConfiguration |
16
|
|
|
{ |
17
|
|
|
/** @inheritdoc */ |
18
|
20 |
|
protected function doLoad(string $file) : void |
19
|
|
|
{ |
20
|
20 |
|
libxml_use_internal_errors(true); |
21
|
|
|
|
22
|
20 |
|
$xml = new DOMDocument(); |
23
|
20 |
|
$xml->load($file); |
24
|
|
|
|
25
|
20 |
|
$xsdPath = __DIR__ . DIRECTORY_SEPARATOR . 'XML' . DIRECTORY_SEPARATOR . 'configuration.xsd'; |
26
|
|
|
|
27
|
20 |
|
if (! $xml->schemaValidate($xsdPath)) { |
28
|
2 |
|
libxml_clear_errors(); |
29
|
|
|
|
30
|
2 |
|
throw XmlNotValid::new(); |
31
|
|
|
} |
32
|
|
|
|
33
|
18 |
|
$xml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA); |
34
|
18 |
|
$config = []; |
35
|
|
|
|
36
|
18 |
|
if (isset($xml->name)) { |
37
|
14 |
|
$config['name'] = (string) $xml->name; |
38
|
|
|
} |
39
|
|
|
|
40
|
18 |
|
if (isset($xml->table['name'])) { |
41
|
14 |
|
$config['table_name'] = (string) $xml->table['name']; |
42
|
|
|
} |
43
|
|
|
|
44
|
18 |
|
if (isset($xml->table['column'])) { |
45
|
10 |
|
$config['column_name'] = (string) $xml->table['column']; |
46
|
|
|
} |
47
|
|
|
|
48
|
18 |
|
if (isset($xml->table['column_length'])) { |
49
|
10 |
|
$config['column_length'] = (int) $xml->table['column_length']; |
50
|
|
|
} |
51
|
|
|
|
52
|
18 |
|
if (isset($xml->table['executed_at_column'])) { |
53
|
10 |
|
$config['executed_at_column_name'] = (string) $xml->table['executed_at_column']; |
54
|
|
|
} |
55
|
|
|
|
56
|
18 |
|
if (isset($xml->{'migrations-namespace'})) { |
57
|
13 |
|
$config['migrations_namespace'] = (string) $xml->{'migrations-namespace'}; |
58
|
|
|
} |
59
|
|
|
|
60
|
18 |
|
if (isset($xml->{'organize-migrations'})) { |
61
|
5 |
|
$config['organize_migrations'] = (string) $xml->{'organize-migrations'}; |
62
|
|
|
} |
63
|
|
|
|
64
|
18 |
|
if (isset($xml->{'migrations-directory'})) { |
65
|
13 |
|
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'}); |
66
|
|
|
} |
67
|
|
|
|
68
|
18 |
|
if (isset($xml->migrations->migration)) { |
69
|
1 |
|
$migrations = []; |
70
|
|
|
|
71
|
1 |
|
foreach ($xml->migrations->migration as $migration) { |
72
|
1 |
|
$attributes = $migration->attributes(); |
73
|
|
|
|
74
|
1 |
|
$version = (string) $attributes['version']; |
75
|
1 |
|
$class = (string) $attributes['class']; |
76
|
|
|
|
77
|
1 |
|
$migrations[] = [ |
78
|
1 |
|
'version' => $version, |
79
|
1 |
|
'class' => $class, |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
1 |
|
$config['migrations'] = $migrations; |
84
|
|
|
} |
85
|
|
|
|
86
|
18 |
|
$this->setConfiguration($config); |
87
|
17 |
|
} |
88
|
|
|
} |
89
|
|
|
|