<?php
require_once('../../settings.php');
function_exists('require_once_path') or require $GLOBALS['library'].'requirepath.php';
require_once_path($GLOBALS['library'].'autoload/');
class_exists('XMLFS') or require $GLOBALS['filesystemsLibrary'].'XMLFS.php';
$GLOBALS['filesystem'] = new XMLFS($GLOBALS['filesystems'].'mocovi.de.xml');
$GLOBALS['definitions'] = $GLOBALS['absolutepath'].'mocovi/definitions/';
$extension = '.rng';
function setOptions(DomNode $root, $control)
{
if(count($options = ControlFactory::createVirtual($control)->getDefaultOptions()) > 0)
{
$root->appendChild($interleave = $root->ownerDocument->createElement('interleave'));
foreach($options as $option => $value)
{
$interleave->appendChild($attribute = $root->ownerDocument->createElement('attribute'));
$attribute->setAttribute('name', $option);
// $attribute->appendChild($root->ownerDocument->createElement('text')); // Not necessary
}
}
}
foreach(ControlFactory::getAvailableControls() as $control)
{
$dom = new DomDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->appendChild($root = $dom->createElementNS('http://relaxng.org/ns/structure/1.0', 'element'));
$root->setAttribute('name', $control);
$root->setAttribute('ns', $GLOBALS['filesystem']->namespace);
setOptions($root, $control);
$root->appendChild($zeroOrMore = $root->ownerDocument->createElement('zeroOrMore'));
$zeroOrMore->appendChild($any = $root->ownerDocument->createElement('anyName'));
//$interleave->
file_put_contents($GLOBALS['definitions'].$control.$extension, $dom->saveXML());
chmod($GLOBALS['definitions'].$control.$extension, 0777);
}