Public paste
controller
By: ILLI | Date: Mar 20 2010 16:46 | Format: PHP | Expires: never | Size: 3.64 KB | Hits: 972

  1. <?php
  2.  
  3.         ABSTRACT CLASS ILLI_Controller
  4.         {
  5.        
  6.                 private $_root = NULL;
  7.                 private $_layoutDir = '';
  8.                 private $_contentBuffer;
  9.                
  10.                 final public function __construct(&$_root)
  11.                 {
  12.                         $this->_root =& $_root;
  13.                 }
  14.                
  15.                 final public function __get($name)
  16.                 {                                      
  17.                         return $this->$name;
  18.                 }
  19.                
  20.                 final public function render()
  21.                 {
  22.                         if($this->_root->Frontend->View->headIncludeView())
  23.                         {              
  24.                                 if($this->_root->Frontend->View->headIncludeLayout())
  25.                                 {                              
  26.                                         $this->_layoutDir = $this->_root->Boot->System->Registry->get()->APP_DIR->LAYOUTS
  27.                                                 .$this->_root->Frontend->View->headLayout()
  28.                                                 .DIRECTORY_SEPARATOR;
  29.                                        
  30.                                         try
  31.                                         {
  32.                                                 if(!is_dir($this->_layoutDir))
  33.                                                         throw new ILLI_SequenceOutput_Exception
  34.                                                                 ('Layout-directory '.$this->_layoutDir.' not found.');
  35.                                                                
  36.                                                 if(!is_file($this->_layoutDir.'document.php'))
  37.                                                         throw new ILLI_SequenceOutput_Exception
  38.                                                                 ('Layout-document not found in '.$this->_layoutDir.'document.php.');
  39.                                                
  40.                                         }
  41.                                         catch(ILLI_SequenceOutput_Exception $e){$e->w();}
  42.                                        
  43.                                         $this->_view()->bufferContent();
  44.                                        
  45.                                         ob_start();
  46.                                         require_once $this->_layoutDir.'document.php';                                 
  47.                                         return ob_get_clean();
  48.                                 }
  49.                                 else
  50.                                 {
  51.                                         $this->_view()->bufferContent();
  52.                                         return $this->_view()->buffer()->content;
  53.                                 }
  54.                         }
  55.                 }
  56.                
  57.                 protected function _uri($nodename, array $args = array())
  58.                 {
  59.                         $result = $this->_root->Boot->Kernel->Dispatcher->createUri($nodename, $args);
  60.                         return $result;
  61.                 }
  62.                
  63.                 protected function _redirect($route = '')
  64.                 {
  65.                         try
  66.                         {
  67.                                 if(!is_string($route))
  68.                                         throw new ILLI_Controller_Exception
  69.                                                 ('invalid redirect route.');
  70.                                                
  71.                                         $args = func_get_args();
  72.                                         array_shift($args);
  73.                                
  74.                                         $this->_status('301');
  75.                                                
  76.                                         $this->_root->Boot->System->Registry->add('HEADER', 'location',
  77.                                                 $this->_uri($route, $args)->absolute);
  78.                                        
  79.                                         $this->_view()->headDisableLayout();
  80.                         }
  81.                         catch(ILLI_Controller_Exception $e){$e->w();}
  82.                        
  83.                         return $this;
  84.                 }
  85.                
  86.                
  87.                 protected function _view()
  88.                 {
  89.                         return $this->_root->Frontend->View;
  90.                 }
  91.                
  92.                 protected function _db()
  93.                 {
  94.                         return $this->_root->Api->Database;
  95.                 }
  96.                
  97.                
  98.                 protected function _parameter()
  99.                 {
  100.                         $params = $this->_root->Boot->System->Registry->get()->DISPATCH->ROUTE->variables;
  101.                        
  102.                         if(is_array($params))
  103.                                 $result = new ILLI_ArrayObject($params);
  104.                         else
  105.                                 $result = new ILLI_ArrayObject();
  106.                                
  107.                         $result->setFlags(ILLI_ArrayObject::ARRAY_AS_PROPS);
  108.                        
  109.                         return $result;
  110.                 }
  111.                
  112.                
  113.                 protected function _get()
  114.                 {
  115.                         $result = new ILLI_ArrayObject($this->_root->Boot->System->Registry->get()->PARAMS->GET);
  116.                         $result->setFlags(ILLI_ArrayObject::ARRAY_AS_PROPS);
  117.                        
  118.                         return $result;
  119.                 }
  120.                
  121.                
  122.                 protected function _post()
  123.                 {
  124.                         $result = new ILLI_ArrayObject($this->_root->Boot->System->Registry->get()->PARAMS->POST);
  125.                         $result->setFlags(ILLI_ArrayObject::ARRAY_AS_PROPS);
  126.                        
  127.                         return $result;
  128.                 }
  129.                
  130.                
  131.                 protected function _form()
  132.                 {
  133.                         return $this->_root->Frontend->Form;
  134.                 }
  135.                
  136.                
  137.                
  138.                 protected function _status($statuscode = '200')
  139.                 {
  140.                         $REGISTRY = $this->_root->Boot->System->Registry;
  141.                         $header   = $REGISTRY->get()->HEADER;
  142.  
  143.                         if(isset($header->status))
  144.                                 $REGISTRY->remove('HEADER', 'status');
  145.                        
  146.                         $REGISTRY->add('HEADER', 'status', $statuscode);
  147.                 }
  148.         }