Пример #1
0
 public function instances($product, $name)
 {
     $query = Flight::request()->query;
     $version = $query->version;
     $page = (int) $query->page;
     if ($page < 1) {
         $page = 1;
     }
     $limit = 50;
     $fromIndex = $limit * ($page - 1);
     $pkg = new Pkg();
     $info = $pkg->getPackageInfo($product, $name);
     if ($info) {
         $path = $info['path'];
     } else {
         Flight::json(null, 404);
     }
     // 过滤IP
     $ips = $query->ips;
     if ($ips) {
         $targetIps = explode(',', $ips);
     } else {
         $targetIps = null;
     }
     // 过滤IP时,不分页
     if (!empty($targetIps)) {
         $fromIndex = $limit = 0;
     }
     $options = compact('version', 'targetIps');
     $pageOptions = compact('fromIndex', 'limit');
     // 分页
     if ($limit) {
         $pkg->multi();
         $pkg->getInstanceCount($path, $options);
         $pkg->getInstanceList($path, $options + $pageOptions);
         $rets = $pkg->exec();
         $count = array_shift($rets);
         $list = array_shift($rets);
         // 控制 Curl 请求错误
         $this->handleCurlError($pkg, 0);
         $this->handleCurlError($pkg, 1);
         // 不分页
     } else {
         $list = $pkg->getInstanceList($path, $options + $pageOptions);
         // 控制 Curl 请求错误
         $this->handleCurlError($pkg);
         $count = array('total' => count($list));
     }
     Flight::json(array('total' => $count['total'], 'instanceList' => $list, 'info' => array('packageUser' => $info['user'], 'frameworkType' => $info['frameworkType'])));
 }