public static function getDependResource($resources, $asyncs = true)
 {
     $dependResources = array();
     //$dependResources = $resources;
     $depends = $resources;
     while (!empty($depends)) {
         $last = end($depends);
         array_pop($depends);
         $id = $last['id'];
         if (isset($dependResources[$id])) {
             continue;
         }
         $dependResources[$id] = $last;
         $lastDepends = self::getDepend($last, $asyncs);
         if (!empty($lastDepends)) {
             $depends = BigPipe::array_merge($depends, $lastDepends);
         }
     }
     return array_reverse($dependResources, true);
 }
 /**
  * 按Quickling模式输出一个pagelet
  *
  * @param PageletContext $context
  */
 protected function outputPagelet($pagelet)
 {
     $resourceMap = array();
     $hooks = array();
     $config = $this->getPageletConfig($pagelet, $html, $resourceMap, $hooks);
     $config['quickling'] = true;
     //设置资源表
     if (!empty($resourceMap)) {
         $resourceMap = BigPipeResource::pathToResource($resourceMap);
         $resourceMap = BigPipeResource::getDependResource($resourceMap);
         $resourceMap = BigPipe::array_merge($resourceMap, $this->loadedResource);
         $outputMap = array();
         foreach ($resourceMap as $id => $resource) {
             if (isset(BigPipeResource::$knownResources[$id])) {
                 continue;
             }
             $requires = $resource['requires'];
             unset($resource['requires']);
             unset($resource['requireAsyncs']);
             $requireIds = array();
             if (!empty($requires)) {
                 $requires = BigPipeResource::pathToResource($requires);
                 $requireIds = array_keys($requires);
             }
             $resource['deps'] = $requireIds;
             $resource['mods'] = $resource['defines'];
             unset($resource['defines']);
             unset($resource['id']);
             $outputMap[$id] = $resource;
             BigPipeResource::$knownResources[$id] = $resource;
         }
     }
     $config["resourceMap"] = $outputMap;
     return $config;
 }
 /**
  * 按Quickling模式输出一个pagelet
  *
  * @param PageletContext $context
  */
 protected function outputPagelet($pagelet)
 {
     $resourceMap = array();
     $hooks = array();
     $config = $this->getPageletConfig($pagelet, $html, $resourceMap, $hooks);
     $config['quickling'] = true;
     if (!empty($hooks)) {
         foreach ($hooks as $id => $hook) {
             // echo "BigPipe.hooks[\"$id\"]=function(){{$hook}};\n";
         }
     }
     //设置资源表
     if (!empty($resourceMap)) {
         $resourceMap = BigPipeResource::pathToResource($resourceMap);
         $resourceMap = BigPipeResource::getDependResource($resourceMap);
         $resourceMap = BigPipe::array_merge($resourceMap, $this->loadedResource);
         $outputMap = array();
         foreach ($resourceMap as $id => $resource) {
             if (isset(BigPipeResource::$knownResources[$id])) {
                 continue;
             }
             $requires = $resource['requires'];
             unset($resource['requires']);
             unset($resource['requireAsyncs']);
             $requireIds = array();
             if (!empty($requires)) {
                 $requires = BigPipeResource::pathToResource($requires);
                 $requireIds = array_keys($requires);
             }
             $resource['deps'] = $requireIds;
             $resource['mods'] = $resource['defines'];
             unset($resource['defines']);
             unset($resource['id']);
             $outputMap[$id] = $resource;
             BigPipeResource::$knownResources[$id] = $resource;
         }
         //echo "BigPipe.setResourceMap(", json_encode($outputMap), ");\n";
     }
     $config["resourceMap"] = $outputMap;
     return $config;
     //echo json_encode($config);
     //输出 pagelet 配置
     //echo "BigPipe.onPageletArrive(", json_encode($config), ");\n";
     //echo "</script>";
 }
 protected function outputPagelet($pagelet)
 {
     $resourceMap = array();
     $hooks = array();
     $config = $this->getPageletConfig($pagelet, $html, $resourceMap, $hooks);
     // 输出注释里的 HTML
     if (!empty($html)) {
         echo "\n" . $html;
     }
     echo "\n<script>\"use strict\";\n";
     // 输出函数
     if (!empty($hooks)) {
         foreach ($hooks as $id => $hook) {
             echo "BigPipe.hooks[\"{$id}\"]=function(){{$hook}};\n";
         }
     }
     //设置资源表
     if (!empty($resourceMap)) {
         $resourceMap = BigPipeResource::pathToResource($resourceMap);
         $resourceMap = BigPipeResource::getDependResource($resourceMap);
         $resourceMap = BigPipe::array_merge($resourceMap, $this->loadedResource);
         $outputMap = array();
         foreach ($resourceMap as $id => $resource) {
             if (isset(BigPipeResource::$knownResources[$id])) {
                 continue;
             }
             $requires = $resource['requires'];
             unset($resource['requires']);
             unset($resource['requireAsyncs']);
             $requireIds = array();
             if (!empty($requires)) {
                 $requires = BigPipeResource::pathToResource($requires);
                 $requireIds = array_keys($requires);
             }
             $resource['deps'] = $requireIds;
             $resource['mods'] = $resource['defines'];
             unset($resource['defines']);
             unset($resource['id']);
             $outputMap[$id] = $resource;
             BigPipeResource::$knownResources[$id] = $resource;
         }
         echo "BigPipe.setResourceMap(", json_encode($outputMap), ");\n";
     }
     //输出 pagelet 配置
     echo "BigPipe.onPageletArrive(", json_encode($config), ");\n";
     echo "</script>";
 }