File modules/template_engine/components/XSDGenerator.php

Last commit: Wed Nov 11 20:29:27 2020 +0100	Jan Dankert	Allow HTML subelements in the component XML schema.
1 <?php 2 /** 3 * Using the Component classes and generating a XSD-File. 4 */ 5 6 use util\FileUtils; 7 8 require(__DIR__.'/../../util/FileUtils.class.php'); 9 10 // Baseclass of all components. 11 require('html/Component.class.php'); 12 require('html/HtmlComponent.class.php'); 13 require('html/FieldComponent.class.php'); 14 15 echo "XSD Generator\n\n"; 16 17 $folder = FileUtils::readDir(__DIR__ . '/html'); 18 19 $componentsFile = @fopen(__DIR__ . '/components.ini', 'w'); 20 $xsdFile = @fopen(__DIR__ . '/template.xsd', 'w'); 21 22 fwrite($componentsFile, '# generated by XSDGenerator. do not change manually.' . "\n"); 23 fwrite($xsdFile, '<?xml version="1.0" encoding="utf-8"?> 24 <xsd:schema xmlns="http://www.openrat.de/template" 25 targetNamespace="http://www.openrat.de/template" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 26 elementFormDefault="qualified" attributeFormDefault="unqualified">' . "\n". 27 '<!-- generated by XSDGenerator. do not change manually -->'."\n"); 28 29 // Only directories 30 $folder = array_filter( $folder,function($name) { 31 return substr($name,0,10) == 'component_'; 32 } ); 33 // Cut 'component_' from directory names 34 $folder = array_map( function($name) { 35 return substr($name,10); 36 }, $folder ); 37 38 // Sort... 39 asort($folder); 40 41 foreach ($folder as $componentName) { 42 43 echo 'Working on component: ' . $componentName . "\n"; 44 fwrite($componentsFile, $componentName . " = \n"); 45 46 fwrite($xsdFile, '<xsd:element name="' . $componentName . '" type="' . $componentName . 'Type" />' 47 .'<xsd:complexType name="' . $componentName . 'Type">'); 48 49 // Allow HTML children 50 //fwrite($xsdFile, '<xsd:openContent mode="interleave">'. 51 // '<xsd:any namespace="http://www.w3.org/1999/xhtml" />'. 52 // '</xsd:openContent>'); 53 54 // Allowed Child-Elements (all) 55 fwrite($xsdFile, '<xsd:choice maxOccurs="unbounded" minOccurs="0">'); 56 foreach ($folder as $cName) { 57 fwrite($xsdFile, '<xsd:element ref="' . $cName . '" maxOccurs="unbounded" minOccurs="0" />'); 58 } 59 60 fwrite($xsdFile,'<xsd:any namespace="http://www.w3.org/1999/xhtml" />' ); 61 62 fwrite($xsdFile, '</xsd:choice>'); 63 64 65 $className = 'template_engine\\components\\html\\component_'.$componentName.'\\' . ucfirst($componentName) . 'Component'; 66 $vars = get_class_vars($className); 67 foreach ($vars as $name => $value) { 68 if (is_bool($value)) 69 $xsdtype = 'xsd:boolean'; 70 elseif (is_numeric($value)) 71 $xsdtype = 'xsd:int'; 72 else 73 $xsdtype = 'xsd:string'; 74 75 76 fwrite($xsdFile, '<xsd:attribute name="' . $name . '" type="' . $xsdtype . '" />'); 77 } 78 79 80 fwrite($xsdFile, '</xsd:complexType>'); 81 82 } 83 84 fwrite($xsdFile, '</xsd:schema>'); 85 86 fclose($xsdFile); 87 fclose($componentsFile); 88 89 echo "Finished.\n";
Download modules/template_engine/components/XSDGenerator.php
History Wed, 11 Nov 2020 20:29:27 +0100 Jan Dankert Allow HTML subelements in the component XML schema. Sat, 17 Oct 2020 22:24:58 +0200 Jan Dankert Fix: XSD must contain all subelements per element; New: Component 'fieldset'. Sat, 17 Oct 2020 01:29:22 +0200 Jan Dankert Fix: XSD-Compiler was broken since the last components refactoring. Fri, 21 Aug 2020 00:22:13 +0200 Jan Dankert Refactoring: Collect all frontend compiler scripts in update.php. Compiling of CSS and JS was extracted to a new TemplateCompiler. JS and CSS is now collected in a new openrat.[min.][js|css]. Mon, 24 Feb 2020 18:36:11 +0100 Jan Dankert Documentation added. Sat, 22 Feb 2020 23:58:02 +0100 Jan Dankert Refactoring: Namespacing for module 'util'. Sat, 22 Feb 2020 00:46:59 +0100 Jan Dankert Refactoring: Renaming template-engine to template_engine because '-' is no valid namespace char.