示例#1
0
 /**
  * Downloads the composer packages data from packagist.org
  *
  * @param  string $packageName The name of composer package.
  * @return array               The parsed json response.
  *
  * @see https://packagist.org/apidoc
  */
 private function downloadPackagistPackageData($packageName)
 {
     $url = $this->packagistBaseUrl . $packageName . '.json';
     $this->cache->setNamespace(sha1(__CLASS__));
     $item = $this->cache->getItem(sha1($url));
     $data = $item->get();
     if ($item->isMiss()) {
         $item->lock();
         $response = $this->http->request('GET', $url);
         $data = json_decode($response->getBody(), true)['package'];
         $this->cache->save($item->set($data));
     }
     return $data;
 }
示例#2
0
 /**
  * Given the path to a composer file we return it's json as an array.
  *
  * @param  string $file
  * @return array
  */
 private function readFile($file)
 {
     $this->cache->setNamespace(sha1(__CLASS__));
     $item = $this->cache->getItem(sha1($file));
     $data = $item->get();
     if ($item->isMiss()) {
         $item->lock();
         if ($this->filesystem->has($file)) {
             $data = json_decode($this->filesystem->read($file), true);
         } else {
             throw new ComposerFileNotFound($this->filesystem->getAdapter()->applyPathPrefix($file));
         }
         $this->cache->save($item->set($data));
     }
     return $data;
 }