Backend\Modules\Locale\Engine\Model::createXMLForExport PHP Method

createXMLForExport() public static method

Create an XML-string that can be used for export.
public static createXMLForExport ( array $items ) : string
$items array The items.
return string
    public static function createXMLForExport(array $items)
    {
        $charset = BackendModel::getContainer()->getParameter('kernel.charset');
        $xml = new \DOMDocument('1.0', $charset);
        // set some properties
        $xml->preserveWhiteSpace = false;
        $xml->formatOutput = true;
        // locale root element
        $root = $xml->createElement('locale');
        $xml->appendChild($root);
        // loop applications
        foreach ($items as $application => $modules) {
            // create application element
            $applicationElement = $xml->createElement($application);
            $root->appendChild($applicationElement);
            // loop modules
            foreach ($modules as $module => $types) {
                // create application element
                $moduleElement = $xml->createElement($module);
                $applicationElement->appendChild($moduleElement);
                // loop types
                foreach ($types as $type => $items) {
                    // loop items
                    foreach ($items as $name => $translations) {
                        // create application element
                        $itemElement = $xml->createElement('item');
                        $moduleElement->appendChild($itemElement);
                        // attributes
                        $itemElement->setAttribute('type', self::getTypeName($type));
                        $itemElement->setAttribute('name', $name);
                        // loop translations
                        foreach ($translations as $translation) {
                            // create translation
                            $translationElement = $xml->createElement('translation');
                            $itemElement->appendChild($translationElement);
                            // attributes
                            $translationElement->setAttribute('language', $translation['language']);
                            // set content
                            $translationElement->appendChild(new \DOMCdataSection($translation['value']));
                        }
                    }
                }
            }
        }
        return $xml->saveXML();
    }

Usage Example

Esempio n. 1
0
 /**
  * Create the XML based on the locale items.
  */
 private function createXML()
 {
     $charset = BackendModel::getContainer()->getParameter('kernel.charset');
     // create XML
     $xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
     // xml headers
     header('Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"');
     header('Content-Type: application/octet-stream;charset=' . $charset);
     header('Content-Length: ' . strlen($xmlOutput));
     // output XML
     echo $xmlOutput;
     exit;
 }
All Usage Examples Of Backend\Modules\Locale\Engine\Model::createXMLForExport