Beispiel #1
0
 /**
  * @param string        $apiKey
  * @param Region        $region
  * @param PoolInterface $cache
  */
 public function __construct($apiKey, Region $region, PoolInterface $cache)
 {
     $this->apiKey = $apiKey;
     $this->cache = $cache;
     $this->region = $region;
     $this->version = new Version(static::VERSION, dirname(dirname(__DIR__)));
     $this->cache->setNamespace(str_replace('\\', '', get_class($this)));
 }
Beispiel #2
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;
 }
Beispiel #3
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;
 }
 /**
  * @param Driver             $driver
  * @param PoolInterface|null $pool
  */
 public function __construct(Driver $driver, PoolInterface $pool = null)
 {
     $this->driver = $driver;
     $this->pool = $pool ?: new Pool();
     $this->pool->setNamespace('beatswitch/lock');
 }