Пример #1
0
 /**
  * \algorithm
  * layoutPath:
  * 		projectLayout = Path::currentProject(apps.layout.+controller.@layout.php)
  * 		if exists(projectLayout)
  * 			return projectLayout
  * 		else return default Layout
  * 
  * paramPath:
  * 		projectParam = Path::currentProject(apps.layout.+controller.@param.php)
  * 		if exists(projectParam)
  * 			return projectParam
  * 		else return default param
  * 
  * viewPath:
  * 		return Path::currentProject(apps.layout.+controller.-method.@view.php)
  * 
  * controllerPath:
  * 		return Path::currentProject(apps.+controller)
  * 
  * processView:
  * 		require(viewPath())
  * 
  * main:
  * 		require(paramPath())
  * 		require(controllerPath())
  * 		startOutputBuffering()
  * 		$controller = new Controller();
  * 		closure syncVars(&$controller){
  * 			foreach($controller->data as $key => &$value){
  * 				local $key = $value;
  * 			}
  * 			processView()
  * 		}
  * 		$this->viewContents = getOutputBufferContents()
  * 		endOutputBuffering()
  * 		startOutputBuffering()
  * 		require(layoutPath())
  * 		$response = getOutputBufferContents()
  * 		endOutputBuffering()
  * 
  * \endalgorithm
  */
 public function run()
 {
     $controller = $this->executeLogic();
     //$this->storeXDO($controller->xdo);
     //{ Make Variables Accessible to View
     $data = $controller->data;
     if (isset($controller->xdo)) {
         $xdo = $controller->xdo;
     }
     if (isset($controller->session)) {
         $session = $controller->session;
     }
     $meta = $controller->meta;
     //}
     //{ Load The View
     if (ControllerTray::instance()->renderView) {
         if (isset($this->_methodReturn) && is_int($this->_methodReturn) && $this->_methodReturn == -1) {
             return;
         }
         $__viewName = $this->view();
         ob_start();
         $scope = function () use($__viewName, $controller, $data, $session, $xdo, $meta) {
             require $__viewName;
         };
         $scope();
         $this->viewContents = ob_get_contents();
         ob_end_clean();
         if (ControllerTray::instance()->bongParsing) {
             $parser = new \SuSAX\Parser(new BongParser(function ($spiritName, $methodName, $arguments, $tagName, $instanceId = null) use($controller) {
                 switch ($tagName) {
                     case 'spirit':
                         return !$instanceId ? $controller->spirit($spiritName)->call($methodName, $arguments) : $controller->spirit($spiritName)->instance($instanceId)->call($methodName, $arguments);
                         break;
                 }
             }));
             $parser->setNsFocus('bong');
             $parser->setText($this->viewContents);
             $this->viewContents = $parser->parse();
         }
         if ($this->_systemView) {
             $controller->dumpStrap();
         }
     }
     //}
     if (ControllerTray::instance()->renderView && ControllerTray::instance()->renderLayout) {
         /// < Layout cannot be rendered If no View is rendered
         $this->mergeParams();
         $params = $this->_arrangedParams;
         ob_start();
         require $this->layout();
         $this->responseBuffer = ob_get_contents();
         ob_end_clean();
     } else {
         if (ControllerTray::instance()->renderView) {
             $this->responseBuffer = ControllerTray::instance()->trim ? trim($this->viewContents) : $this->viewContents;
         } else {
             if (isset($this->_methodReturn)) {
                 switch (ControllerTray::instance()->responseType) {
                     case 'scrap/xml':
                         http::contentType('text/xml');
                         $packer = new XMLPacker($this->_methodReturn);
                         $this->responseBuffer = $packer->toXML()->saveXML();
                         break;
                     case 'scrap/json':
                         http::contentType('application/json');
                         $this->responseBuffer = json_encode($this->_methodReturn);
                         break;
                     case 'scrap/plain':
                     default:
                         http::contentType('text/plain');
                         $this->responseBuffer = $this->_methodReturn;
                 }
             }
         }
     }
     if (ControllerTray::instance()->xsltView) {
         $this->processXSLView($controller->storage());
     }
     //echo $this->responseBuffer;
 }
Пример #2
0
 /**
  * Converts the DataObject to XML DOM
  * @return DomDocument
  */
 public function toXML()
 {
     $xmlSerializer = new XMLPacker($this);
     return $xmlSerializer->toXML();
 }