Пример #1
0
 /**
  * Get Core Branches with further informations
  */
 protected function getCoreBranches()
 {
     $branches = array();
     $http = new \WireHttp();
     $http->setHeader('User-Agent', 'ProcessWireUpgrade');
     $json = $http->get(self::branchesURL);
     if (!$json) {
         $error = "Error loading GitHub branches " . self::branchesURL;
         throw new \WireException($error);
         $this->error($error);
         return array();
     }
     $data = json_decode($json, true);
     if (!$data) {
         $error = "Error JSON decoding GitHub branches " . self::branchesURL;
         throw new \WireException($error);
         $this->error($error);
         return array();
     }
     foreach ($data as $key => $info) {
         $name = $info['name'];
         $branch = array('name' => $name, 'title' => ucfirst($name), 'zipURL' => str_replace('{branch}', $name, self::zipURL), 'version' => '', 'versionURL' => str_replace('{branch}', $name, self::versionURL));
         if ($name == 'dev') {
             $branch['title'] = 'Development';
         }
         if ($name == 'master') {
             $branch['title'] = 'Stable/Master';
         }
         $content = $http->get($branch['versionURL']);
         if (!preg_match_all('/const\\s+version(Major|Minor|Revision)\\s*=\\s*(\\d+)/', $content, $matches)) {
             $branch['version'] = '?';
             continue;
         }
         $version = array();
         foreach ($matches[1] as $key => $var) {
             $version[$var] = (int) $matches[2][$key];
         }
         $branch['version'] = "{$version['Major']}.{$version['Minor']}.{$version['Revision']}";
         $branches[$name] = $branch;
     }
     return $branches;
 }