XmlPersistor.php 846 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Setup;
  7. /**
  8. * Persist listened schema to db_schema.xml file.
  9. */
  10. class XmlPersistor
  11. {
  12. /**
  13. * Persist XML object to file.
  14. *
  15. * @param \SimpleXMLElement $simpleXMLElement
  16. * @param $path
  17. */
  18. public function persist(\SimpleXMLElement $simpleXMLElement, $path)
  19. {
  20. $dom = new \DOMDocument('1.0');
  21. $dom->preserveWhiteSpace = false;
  22. $dom->formatOutput = true;
  23. $dom->loadXML($simpleXMLElement->asXML());
  24. file_put_contents(
  25. $path,
  26. str_replace(
  27. ' xmlns:xsi="xsi"', //replace namespace, as we do not need it for xsi namespace
  28. '',
  29. $dom->saveXML()
  30. )
  31. );
  32. }
  33. }