示例#1
0
 /**
  * @param Project $project
  * @param bool|false $reset
  */
 public function prepare(Project $project, $reset = false)
 {
     $cid_parts = array('release_history', $project->getProject(), $project->getCore());
     $cid = implode(':', $cid_parts);
     $data = false;
     if ($this->cache && !$reset) {
         $data = $this->cache->fetch($cid);
     }
     // If not in cache, load from remote.
     if ($data === false) {
         $url = $project->getStatusUrl() . '/' . $project->getProject() . '/' . $project->getCore();
         // Todo: use guzzle library.
         $content = file_get_contents($url);
         $data = $this->parseUpdateXml($content);
         // If data, store into cache.
         if ($this->cache && !empty($data)) {
             $this->cache->save($cid, $data, 1800);
         }
     }
     $data += array('project_status' => '', 'default_major' => '', 'recommended_major' => '', 'supported_majors' => '');
     // Hydrate release objects.
     if (isset($data['releases']) && is_array($data['releases'])) {
         foreach ($data['releases'] as $key => $value) {
             $data['releases'][$key] = new Release($value);
         }
         $project->setReleases($data['releases']);
     } else {
         $data['releases'] = array();
     }
     if (!empty($data['type'])) {
         $project->setProjectType($data['type']);
     } else {
         $project->setProjectType(Project::TYPE_UNKNOWN);
     }
     $this->data = (array) $data;
 }