openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

XSDGenerator.php (2280B)


      1 <?php
      2 /**
      3  * Using the Component classes and generating a XSD-File.
      4  */
      5 
      6 error_reporting(E_ALL);
      7 
      8 require('../../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 header('Content-Type: text/plain');
     15 
     16 echo "XSD Generator\n\n";
     17 
     18 $folder = FileUtils::readDir(__DIR__ . '/html');
     19 
     20 $componentsFile = @fopen(__DIR__ . '/components.ini', 'w');
     21 $xsdFile = @fopen(__DIR__ . '/template.xsd', 'w');
     22 
     23 fwrite($componentsFile, '# generated by XSDGenerator. do not change manually.' . "\n");
     24 fwrite($xsdFile, '<?xml version="1.0" encoding="utf-8"?>
     25 <xsd:schema xmlns="http://www.openrat.de/template"
     26 	targetNamespace="http://www.openrat.de/template" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     27 	elementFormDefault="qualified" attributeFormDefault="unqualified">' . "\n");
     28 
     29 foreach ($folder as $f) {
     30 
     31     $filename = __DIR__ . '/html/' . $f . '/' . ucfirst($f) . '.class.php';
     32 
     33     if (!is_file($filename))
     34         continue;
     35 
     36     echo 'Working on component: ' . $f . "\n";
     37     fwrite($componentsFile, $f . " = \n");
     38 
     39     fwrite($xsdFile, '<xsd:element name="' . $f . '" type="' . $f . 'Type" /><xsd:complexType name="' . $f . 'Type">');
     40 
     41     // Allowed Child-Elements (all)
     42     fwrite($xsdFile, '<xsd:choice maxOccurs="unbounded" minOccurs="0">');
     43     foreach ($folder as $f2) {
     44         $filename2 = __DIR__ . '/html/' . $f2 . '/' . ucfirst($f2) . '.class.php';
     45         if (is_file($filename2))
     46             fwrite($xsdFile, '<xsd:element ref="' . $f2 . '" maxOccurs="unbounded" minOccurs="0" />');
     47     }
     48     fwrite($xsdFile, '</xsd:choice>');
     49 
     50 
     51     $className = 'template_engine\\components\\' . ucfirst($f) . 'Component';
     52     include($filename);
     53     $vars = get_class_vars($className);
     54     foreach ($vars as $name => $value) {
     55         if (is_bool($value))
     56             $xsdtype = 'xsd:boolean';
     57         elseif (is_numeric($value))
     58             $xsdtype = 'xsd:int';
     59         else
     60             $xsdtype = 'xsd:string';
     61 
     62 
     63         fwrite($xsdFile, '<xsd:attribute name="' . $name . '" type="' . $xsdtype . '" />');
     64     }
     65 
     66 
     67     fwrite($xsdFile, '</xsd:complexType>');
     68 
     69 }
     70 
     71 fwrite($xsdFile, '</xsd:schema>');
     72 
     73 fclose($xsdFile);
     74 fclose($componentsFile);
     75 
     76 echo "Finished.\n";