XmlConfiguration.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. namespace Doctrine\DBAL\Migrations\Configuration;
  20. use Doctrine\DBAL\Migrations\MigrationException;
  21. /**
  22. * Load migration configuration information from a XML configuration file.
  23. *
  24. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  25. * @link www.doctrine-project.org
  26. * @since 2.0
  27. * @author Jonathan H. Wage <jonwage@gmail.com>
  28. */
  29. class XmlConfiguration extends AbstractFileConfiguration
  30. {
  31. /**
  32. * @inheritdoc
  33. */
  34. protected function doLoad($file)
  35. {
  36. libxml_use_internal_errors(true);
  37. $xml = new \DOMDocument();
  38. $xml->load($file);
  39. if (!$xml->schemaValidate(__DIR__ . DIRECTORY_SEPARATOR . "XML" . DIRECTORY_SEPARATOR . "configuration.xsd")) {
  40. libxml_clear_errors();
  41. throw MigrationException::configurationNotValid('XML configuration did not pass the validation test.');
  42. }
  43. $xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA);
  44. $config = [];
  45. if (isset($xml->name)) {
  46. $config['name'] = (string) $xml->name;
  47. }
  48. if (isset($xml->table['name'])) {
  49. $config['table_name'] = (string) $xml->table['name'];
  50. }
  51. if (isset($xml->table['column'])) {
  52. $config['column_name'] = (string) $xml->table['column'];
  53. }
  54. if (isset($xml->{'migrations-namespace'})) {
  55. $config['migrations_namespace'] = (string) $xml->{'migrations-namespace'};
  56. }
  57. if (isset($xml->{'organize-migrations'})) {
  58. $config['organize_migrations'] = $xml->{'organize-migrations'};
  59. }
  60. if (isset($xml->{'migrations-directory'})) {
  61. $config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, (string) $xml->{'migrations-directory'});
  62. }
  63. if (isset($xml->migrations->migration)) {
  64. $config['migrations'] = $xml->migrations->migration;
  65. }
  66. $this->setConfiguration($config);
  67. }
  68. }