public function exportFileBased($property)
{
$xmlFile = $this->getPropertyFilePath($property);
$doc = new \DOMDocument();
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;
if (file_exists($path = $this->getJarves()->getRootDir() . '/../' . $xmlFile)) {
$doc->load($path);
} else {
$configElement = $doc->createElement('config');
$doc->appendChild($configElement);
$bundleElement = $doc->createElement('bundle');
$configElement->appendChild($bundleElement);
}
$xpath = new \DOMXPath($doc);
$element = null;
$elements = $xpath->query('/config/bundle/' . $property);
if (0 < $elements->length) {
$element = $elements->item(0);
}
if ($element) {
$newNode = $this->appendXmlProperty($property, $element->parentNode, false);
if ($newNode instanceof \DOMElement) {
$element->parentNode->replaceChild($newNode, $element);
}
} else {
$elements = $xpath->query('/config/bundle');
if (0 < $elements->length) {
$element = $elements->item(0);
}
$this->appendXmlProperty($property, $element, false);
}
$xml = $doc->saveXML();
$xml = substr($xml, strlen('<?xml version="1.0"?>') + 1);
$xml = trim($xml);
return $xml;
}