ManiaLib 1.0b1 API Reference

Source for file ResponseEngine.class.php

Documentation is available at ResponseEngine.class.php

  1. <?php
  2. /**
  3.  * @author Maxime Raoust
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  * @subpackage MVC
  7.  */
  8.  
  9. /**
  10.  * Response engine
  11.  * Allows to pass values between filters, controllers and views
  12.  * @package ManiaLib
  13.  * @subpackage MVC
  14.  * @todo doc
  15.  */
  16. {
  17.     /**
  18.      * @ignore
  19.      */
  20.     private static $instance;
  21.  
  22.     /**#@+
  23.      * @ignore 
  24.      */
  25.     private $vars array();
  26.     private $body '';
  27.     private $views array();
  28.     /**#@-*/
  29.     /**
  30.      * @var DialogHelper 
  31.      * @ignore
  32.      */
  33.     public $dialog;
  34.  
  35.     /**
  36.      * Gets the instance
  37.      * @return ResponseEngine 
  38.      */
  39.     public static function getInstance()
  40.     {
  41.         if (!self::$instance)
  42.         {
  43.             $class = __CLASS__;
  44.             self::$instance new $class;
  45.         }
  46.         return self::$instance;
  47.     }
  48.  
  49.     /**
  50.      * @ignore
  51.      */
  52.     private function __construct({}
  53.  
  54.     /**
  55.      * @ignore
  56.      */
  57.     public function __set($name$value)
  58.     {
  59.         $this->vars[$name$value;
  60.     }
  61.     
  62.     /**
  63.      * @ignore
  64.      */
  65.     public function __get($name)
  66.     {
  67.         if(array_key_exists($name$this->vars))
  68.         {
  69.             return $this->vars[$name];
  70.         }
  71.         else
  72.         {
  73.             return null;
  74.         }
  75.     }
  76.     
  77.     /**
  78.      * @todo doc
  79.      */
  80.     public function get($name$default=null)
  81.     {
  82.         if(array_key_exists($name$this->vars))
  83.         {
  84.             return $this->vars[$name];
  85.         }
  86.         else
  87.         {
  88.             return $default;
  89.         }
  90.     }
  91.     
  92.     /**
  93.      * @todo doc
  94.      */
  95.     public function registerDialog(DialogHelper $dialog)
  96.     {
  97.         if($this->dialog)
  98.         {
  99.             throw new DialogAlreadyRegistered;
  100.         }
  101.         $this->dialog $dialog;
  102.     }
  103.     
  104.     /**
  105.      * @todo doc
  106.      */
  107.     public function registerView($controllerName$actionName)
  108.     {
  109.         $this->views[array($controllerName$actionName);
  110.     }
  111.     
  112.     /**
  113.      * @todo doc
  114.      */
  115.     public function resetViews()
  116.     {
  117.         $this->views array();
  118.     }
  119.     
  120.     /**
  121.      * @todo doc
  122.      */
  123.     public function appendBody($content)
  124.     {
  125.         $this->body .= $content;
  126.     }
  127.     
  128.     /**
  129.      * @ignore
  130.      */
  131.     public function render()
  132.     {
  133.         View::render('header');
  134.         if($this->dialog)
  135.         {
  136.             View::render($this->dialog->controller$this->dialog->action);
  137.             Manialink::disableLinks();
  138.         }
  139.         foreach($this->views as $view)
  140.         {
  141.             View::render($view[0]$view[1]);
  142.         }
  143.         View::render('footer');
  144.         
  145.         header('Content-Type: text/xml; charset=utf-8');
  146.         echo $this->body;
  147.     }
  148. }
  149.  
  150. /**
  151.  * @package ManiaLib
  152.  * @subpackage MVC
  153.  * @ignore
  154.  */
  155. class ResponseEngineException extends MVCException {}
  156.  
  157. /**
  158.  * @package ManiaLib
  159.  * @subpackage MVC
  160.  * @ignore
  161.  */
  162. class DialogAlreadyRegistered extends ResponseEngineException {}
  163.  
  164. ?>