|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Migrations\Configuration; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Migrations\MigrationException; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Load migration configuration information from a XML configuration file. |
|
26
|
|
|
* |
|
27
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
|
28
|
|
|
* @link www.doctrine-project.org |
|
29
|
|
|
* @since 2.0 |
|
30
|
|
|
* @author Jonathan H. Wage <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class XmlConfiguration extends AbstractFileConfiguration |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
19 |
|
protected function doLoad($file) |
|
38
|
|
|
{ |
|
39
|
19 |
|
libxml_use_internal_errors(true); |
|
40
|
19 |
|
$xml = new \DOMDocument(); |
|
41
|
19 |
|
$xml->load($file); |
|
42
|
19 |
|
if (!$xml->schemaValidate(__DIR__ . DIRECTORY_SEPARATOR . "XML" . DIRECTORY_SEPARATOR . "configuration.xsd")) { |
|
43
|
2 |
|
libxml_clear_errors(); |
|
44
|
2 |
|
throw MigrationException::configurationNotValid('XML configuration did not pass the validation test.'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
17 |
|
$xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA); |
|
48
|
17 |
|
$config = []; |
|
49
|
|
|
|
|
50
|
17 |
|
if (isset($xml->name)) { |
|
51
|
13 |
|
$config['name'] = (string) $xml->name; |
|
52
|
13 |
|
} |
|
53
|
17 |
|
if (isset($xml->table['name'])) { |
|
54
|
13 |
|
$config['table_name'] = (string) $xml->table['name']; |
|
55
|
13 |
|
} |
|
56
|
17 |
|
if (isset($xml->table['column'])) { |
|
57
|
8 |
|
$config['column_name'] = (string) $xml->table['column']; |
|
58
|
8 |
|
} |
|
59
|
17 |
|
if (isset($xml->{'migrations-namespace'})) { |
|
60
|
12 |
|
$config['migrations_namespace'] = (string) $xml->{'migrations-namespace'}; |
|
61
|
12 |
|
} |
|
62
|
17 |
|
if (isset($xml->{'organize-migrations'})) { |
|
63
|
5 |
|
$config['organize_migrations'] = $xml->{'organize-migrations'}; |
|
64
|
5 |
|
} |
|
65
|
17 |
|
if (isset($xml->{'migrations-directory'})) { |
|
66
|
12 |
|
$config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'}); |
|
67
|
12 |
|
} |
|
68
|
17 |
|
if (isset($xml->migrations->migration)) { |
|
69
|
1 |
|
$config['migrations'] = $xml->migrations->migration; |
|
70
|
1 |
|
} |
|
71
|
|
|
|
|
72
|
17 |
|
$this->setConfiguration($config); |
|
73
|
16 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|