src/TreeLayoutStack/TemplatingService.php
public function buildLayoutTemplate(\Zend\Mvc\MvcEvent $oEvent){
		$oRequest = $oEvent->getRequest();
		if(!($oRequest instanceof \Zend\Http\Request) || $oRequest->isXmlHttpRequest() || (
    		($oView = $oEvent->getResult()) instanceof \Zend\View\Model\ModelInterface
    		&& $oView->terminate()
    	))return $this;

		//Define current event
		$this->setCurrentEvent($oEvent);

		//Define module Name

		if(($oRouter = $this->getCurrentEvent()->getRouteMatch()) instanceof \Zend\Mvc\Router\RouteMatch)$sModule = current(explode('\\',$oRouter->getParam('controller')));
		if(empty($sModule))$sModule = \TreeLayoutStack\TemplatingConfiguration::DEFAULT_LAYOUT_TREE;

		try{
			//Retrieve template for module
			$oTemplate = $this->getConfiguration()->hasLayoutTreeForModule($sModule)
				?$this->getConfiguration()->getLayoutTreeForModule($sModule)
				:$this->getConfiguration()->getLayoutTreeForModule(\TreeLayoutStack\TemplatingConfiguration::DEFAULT_LAYOUT_TREE);

			//Set layout template and add its children
			$sTemplate = $oTemplate->getConfiguration()->getTemplate();
			if(is_callable($sTemplate))$sTemplate = $sTemplate($this->getCurrentEvent());
			$oEvent->setViewModel($this->setChildrenToView(
				$oEvent->getViewModel()->setTemplate($sTemplate),
				$oTemplate->getChildren()
			));
		}
		catch(\Exception $oException){
			throw new \RuntimeException('Error occured during building layout template process : '.$oException->getMessage(),$oException->getCode(),$oException);
		}
		//Reset current event
		return $this->unsetCurrentEvent();
	}
public function buildLayoutTemplate(\Zend\Mvc\MvcEvent $oEvent){
		$oRequest = $oEvent->getRequest();
		if(!($oRequest instanceof \Zend\Http\Request) || $oRequest->isXmlHttpRequest() || (
    		($oView = $oEvent->getResult()) instanceof \Zend\View\Model\ModelInterface
    		&& $oView->terminate()
    	))return $this;

		//Define current event
		$this->setCurrentEvent($oEvent);

		//Define module Name

		if(($oRouter = $this->getCurrentEvent()->getRouteMatch()) instanceof \Zend\Mvc\Router\RouteMatch)$sModule = current(explode('\\',$oRouter->getParam('controller')));
		if(empty($sModule))$sModule = \TreeLayoutStack\TemplatingConfiguration::DEFAULT_LAYOUT_TREE;

		try{
			//Retrieve template for module
			$oTemplate = $this->getConfiguration()->hasLayoutTreeForModule($sModule)
				?$this->getConfiguration()->getLayoutTreeForModule($sModule)
				:$this->getConfiguration()->getLayoutTreeForModule(\TreeLayoutStack\TemplatingConfiguration::DEFAULT_LAYOUT_TREE);

			//Set layout template and add its children
			$sTemplate = $oTemplate->getConfiguration()->getTemplate();
			if(is_callable($sTemplate))$sTemplate = $sTemplate($this->getCurrentEvent());
			$oEvent->setViewModel($this->setChildrenToView(
				$oEvent->getViewModel()->setTemplate($sTemplate),
				$oTemplate->getChildren()
			));
		}
		catch(\Exception $oException){
			throw new \RuntimeException('Error occured during building layout template process : '.$oException->getMessage(),$oException->getCode(),$oException);
		}
		//Reset current event
		return $this->unsetCurrentEvent();
	}
public function buildLayoutTemplate ( \ Zend \ Mvc \ MvcEvent $ oEvent ) { $ oRequest = $ oEvent -> getRequest ( ) ; if ( ! ( $ oRequest instanceof \ Zend \ Http \ Request ) || $ oRequest -> isXmlHttpRequest ( ) || ( ( $ oView = $ oEvent -> getResult ( ) ) instanceof \ Zend \ View \ Model \ ModelInterface && $ oView -> terminate ( ) ) ) return $ this ; //Define current event $ this -> setCurrentEvent ( $ oEvent ) ; //Define module Name if ( ( $ oRouter = $ this -> getCurrentEvent ( ) -> getRouteMatch ( ) ) instanceof \ Zend \ Mvc \ Router \ RouteMatch ) $ sModule = current ( explode ( '\\' , $ oRouter -> getParam ( 'controller' ) ) ) ; if ( empty ( $ sModule ) ) $ sModule = \ TreeLayoutStack \ TemplatingConfiguration :: DEFAULT_LAYOUT_TREE ; try { //Retrieve template for module $ oTemplate = $ this -> getConfiguration ( ) -> hasLayoutTreeForModule ( $ sModule ) ? $ this -> getConfiguration ( ) -> getLayoutTreeForModule ( $ sModule ) : $ this -> getConfiguration ( ) -> getLayoutTreeForModule ( \ TreeLayoutStack \ TemplatingConfiguration :: DEFAULT_LAYOUT_TREE ) ; //Set layout template and add its children $ sTemplate = $ oTemplate -> getConfiguration ( ) -> getTemplate ( ) ; if ( is_callable ( $ sTemplate ) ) $ sTemplate = $ sTemplate ( $ this -> getCurrentEvent ( ) ) ; $ oEvent -> setViewModel ( $ this -> setChildrenToView ( $ oEvent -> getViewModel ( ) -> setTemplate ( $ sTemplate ) , $ oTemplate -> getChildren ( ) ) ) ; } catch ( \ Exception $ oException ) { throw new \ RuntimeException ( 'Error occured during building layout template process : ' . $ oException -> getMessage ( ) , $ oException -> getCode ( ) , $ oException ) ; } //Reset current event return $ this -> unsetCurrentEvent ( ) ; }
Define layout template
@param \Zend\Mvc\MvcEvent $oEvent
@throws \RuntimeException
@return \TreeLayoutStack\TemplatingService
Define layout template