ManiaLib 1.0b1 API Reference

Source for file Maniacode.class.php

Documentation is available at Maniacode.class.php

  1. <?php
  2. /**
  3.  * @author Philippe Melot
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  */
  7.  
  8. /**
  9.  * @ignore
  10.  */
  11. require_onceAPP_FRAMEWORK_GUI_TOOLKIT_PATH.'standardManiacode.php' );
  12.  
  13. /**
  14.  * Maniacode Toolkit
  15.  * 
  16.  * @package ManiaLib
  17.  * @subpackage ManiacodeToolkit
  18.  */
  19. abstract class Maniacode
  20. {
  21.     /**#@+
  22.      * @ignore
  23.      */
  24.     public static $domDocument;
  25.     public static $parentNodes;
  26.     /**#@-*/
  27.     
  28.     /**
  29.      * Loads the Maniacode GUI Toolkit. This should be called before doing anything with the toolkit
  30.      *
  31.      * @param bool True if you don't want to see a message at the end of the execution of the maniacode
  32.      * @param bool Wheter you want to create the root "<maniacode>" element in the XML
  33.      */
  34.     final public static function load($noconfirmation false$createManialinkElement true)
  35.     {
  36.         self::$domDocument new DOMDocument;
  37.         self::$parentNodes array();
  38.         
  39.         if ($createManialinkElement)
  40.         {
  41.             $maniacode self::$domDocument->createElement('maniacode');
  42.             if($noconfirmation)
  43.                 $maniacode->setAttribute('noconfirmation'$noconfirmation);
  44.             self::$domDocument->appendChild($maniacode);
  45.             self::$parentNodes[$maniacode;
  46.         }
  47.     }
  48.     
  49.     /**
  50.      * Renders the Maniacode if no return the script will be stopped
  51.      * @param bool Whether you want to return the XML instead of printing it
  52.      * @return mixed The XML string if param true, in other case it returns void
  53.      */
  54.     final public static function render($return false)
  55.     {
  56.         if($return)
  57.         {
  58.             return self::$domDocument->saveXML();
  59.         }
  60.         else
  61.         {
  62.             header('Content-Type: text/xml; charset=utf-8');
  63.             echo self::$domDocument->saveXML();
  64.             exit();
  65.         }
  66.     }
  67.     
  68.     /**
  69.      * Append some XML code to the document
  70.      * @param string $XML The given XML
  71.      */
  72.     static function appendXML($XML)
  73.     {
  74.         $doc new DOMDocument();
  75.         $doc->loadXML($XML);
  76.         $node self::$domDocument->importNode($doc->firstChildtrue);
  77.         end(self::$parentNodes)->appendChild($node);
  78.     }
  79. }
  80. ?>