1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Configuration; |
6
|
|
|
|
7
|
|
|
use Doctrine\Migrations\MigrationException; |
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
|
19 |
|
protected function doLoad(string $file) : void |
19
|
|
|
{ |
20
|
19 |
|
libxml_use_internal_errors(true); |
21
|
|
|
|
22
|
19 |
|
$xml = new DOMDocument(); |
23
|
19 |
|
$xml->load($file); |
24
|
|
|
|
25
|
19 |
|
$xsdPath = __DIR__ . DIRECTORY_SEPARATOR . 'XML' . DIRECTORY_SEPARATOR . 'configuration.xsd'; |
26
|
|
|
|
27
|
19 |
|
if (! $xml->schemaValidate($xsdPath)) { |
28
|
2 |
|
libxml_clear_errors(); |
29
|
|
|
|
30
|
2 |
|
throw MigrationException::configurationNotValid('XML configuration did not pass the validation test.'); |
31
|
|
|
} |
32
|
|
|
|
33
|
17 |
|
$xml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA); |
34
|
17 |
|
$config = []; |
35
|
|
|
|
36
|
17 |
|
if (isset($xml->name)) { |
37
|
13 |
|
$config['name'] = (string) $xml->name; |
38
|
|
|
} |
39
|
|
|
|
40
|
17 |
|
if (isset($xml->table['name'])) { |
41
|
13 |
|
$config['table_name'] = (string) $xml->table['name']; |
42
|
|
|
} |
43
|
|
|
|
44
|
17 |
|
if (isset($xml->table['column'])) { |
45
|
8 |
|
$config['column_name'] = (string) $xml->table['column']; |
46
|
|
|
} |
47
|
|
|
|
48
|
17 |
|
if (isset($xml->{'migrations-namespace'})) { |
49
|
12 |
|
$config['migrations_namespace'] = (string) $xml->{'migrations-namespace'}; |
50
|
|
|
} |
51
|
|
|
|
52
|
17 |
|
if (isset($xml->{'organize-migrations'})) { |
53
|
5 |
|
$config['organize_migrations'] = (string) $xml->{'organize-migrations'}; |
54
|
|
|
} |
55
|
|
|
|
56
|
17 |
|
if (isset($xml->{'migrations-directory'})) { |
57
|
12 |
|
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'}); |
58
|
|
|
} |
59
|
|
|
|
60
|
17 |
|
if (isset($xml->migrations->migration)) { |
61
|
1 |
|
$migrations = []; |
62
|
|
|
|
63
|
1 |
|
foreach ($xml->migrations->migration as $migration) { |
64
|
1 |
|
$attributes = $migration->attributes(); |
65
|
|
|
|
66
|
1 |
|
$version = (string) $attributes['version']; |
67
|
1 |
|
$class = (string) $attributes['class']; |
68
|
|
|
|
69
|
1 |
|
$migrations[] = [ |
70
|
1 |
|
'version' => $version, |
71
|
1 |
|
'class' => $class, |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
$config['migrations'] = $migrations; |
76
|
|
|
} |
77
|
|
|
|
78
|
17 |
|
$this->setConfiguration($config); |
79
|
16 |
|
} |
80
|
|
|
} |
81
|
|
|
|