Example #1
0
 public function assemble(Controller $aController)
 {
     // 触发事件
     $arrEventArgvs = array($this, $aController);
     if ($return = EventManager::singleton()->emitEvent(__CLASS__, self::assemble, $arrEventArgvs)) {
         $this->arrAssemblyListRepos = $return->returnValue();
         // 			echo '<pre>' ;
         // 			print_r($return->returnValue()) ;
         // 			echo '</pre>' ;
         return;
     }
     // 正式执行操作
     foreach ($this->arrAssemblyListRepos as $sId => &$arrAssemblyList) {
         if (empty($arrAssemblyList['filter'])) {
             continue;
         }
         if (empty($arrAssemblyList['filter']['view'])) {
             throw new Exception('视图装配单缺少 view 信息。');
         }
         // echo "<br />\r\nassemble list: '", $sId, "'----------<br />\r\n" ;
         if ($arrAssemblyList['filter']['xpaths']) {
             // 使用 xpath , 从视图所属的控制器开始
             if (!($aController = $arrAssemblyList['filter']['view']->controller())) {
                 throw new Exception('视图尚未加入控制器,无法通过 xpath 查找其它视图。');
             }
             $aViewContainer = $aController->mainView();
             // 找指定 xpath 的view
             foreach ($arrAssemblyList['filter']['xpaths'] as $sXPath) {
                 if ($aFoundView = View::findXPath($aViewContainer, $sXPath)) {
                     // echo 'found view by xpath : ' , $sXPath, "<br />\r\n" ;
                     $this->assembleView($arrAssemblyList, $aFoundView);
                 }
             }
         } else {
             // 找 view 的所有下级视图
             foreach ($arrAssemblyList['filter']['view']->iterator() as $aView) {
                 if ($aView->parent() === $arrAssemblyList['filter']['view']) {
                     // echo 'found child view : ' , $aView->xpath(), "<br />\r\n" ;
                     $this->assembleView($arrAssemblyList, $aView);
                 }
             }
         }
         // 不在需要
         unset($arrAssemblyList['filter']);
     }
     // 		echo '<pre>' ;
     // 		$arrAssemblyListRepos = $this->arrAssemblyListRepos ;
     // 		foreach( $arrAssemblyListRepos as $sId=>&$arrAssemblyList )
     // 		{
     // 			if(empty($arrAssemblyList['items']))
     // 			{
     // 				//unset($arrAssemblyListRepos[$sId]) ;
     // 			}
     // 			else
     // 			{
     // 				foreach($arrAssemblyList['items'] as &$arrItem)
     // 				{
     // 					unset($arrItem['object']) ;
     // 				}
     // 			}
     // 		}
     // 		print_r($arrAssemblyListRepos) ;
     // 		echo '</pre>' ;
 }