/** * {@inheritDoc} */ public function getComposerInformation($identifier) { if ($this->fallbackDriver) { return $this->fallbackDriver->getComposerInformation($identifier); } if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && ($res = $this->cache->read($identifier))) { return $this->infoCache[$identifier] = JsonFile::parseJson($res); } $composer = $this->getBaseComposerInformation($identifier); // specials for bitbucket if (!isset($composer['support']['source'])) { $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier; if (array_key_exists($label, $tags = $this->getTags())) { $hash = $tags[$label]; } elseif (array_key_exists($label, $branches = $this->getBranches())) { $hash = $branches[$label]; } if (!isset($hash)) { $composer['support']['source'] = sprintf('https://%s/%s/%s/src', $this->originUrl, $this->owner, $this->repository); } else { $composer['support']['source'] = sprintf('https://%s/%s/%s/src/%s/?at=%s', $this->originUrl, $this->owner, $this->repository, $hash, $label); } } if (!isset($composer['support']['issues']) && $this->hasIssues) { $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository); } $this->infoCache[$identifier] = $composer; if ($this->shouldCache($identifier)) { $this->cache->write($identifier, json_encode($composer)); } } return $this->infoCache[$identifier]; }
/** * @param string $url The url * * @return string The url redirected */ protected function getValidContentUrl($url) { if (null === $this->redirectApi && false !== ($redirectApi = $this->cache->read('redirect-api'))) { $this->redirectApi = $redirectApi; } if (is_string($this->redirectApi) && 0 === strpos($url, $this->getRepositoryApiUrl())) { $url = $this->redirectApi . substr($url, strlen($this->getRepositoryApiUrl())); } return $url; }
/** * {@inheritdoc} */ public function getComposerInformation($identifier) { if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && ($res = $this->cache->read($identifier))) { return $this->infoCache[$identifier] = JsonFile::parseJson($res); } $composer = $this->getBaseComposerInformation($identifier); if ($this->shouldCache($identifier)) { $this->cache->write($identifier, json_encode($composer)); } $this->infoCache[$identifier] = $composer; } return $this->infoCache[$identifier]; }
/** * @param array $cacheCode The cache code * @param Cache $cache The cache filesystem * @param string $type The asset type * @param string $identifier The identifier * @param bool $force Force the read * * @return array|null */ public static function readCache(array $cacheCode, Cache $cache, $type, $identifier, $force = false) { if (array_key_exists($identifier, $cacheCode)) { return $cacheCode[$identifier]; } $data = null; if (self::isSha($identifier) || $force) { $res = $cache->read($type . '-' . $identifier); if ($res) { $data = JsonFile::parseJson($res); } } return $data; }
public function read($file, $staleSince = null) { if ($staleSince && file_exists($this->getRoot() . $file)) { try { $dt = new \DateTime($staleSince); $repomtime = (int) $dt->format('U'); $filemtime = filemtime($this->getRoot() . $file); if ($filemtime < $repomtime) { unlink($this->getRoot() . $file); } } catch (\Exception $e) { } } return parent::read($file); }
/** * {@inheritDoc} */ public function getComposerInformation($identifier) { if ($this->gitDriver) { return $this->gitDriver->getComposerInformation($identifier); } if (preg_match('{[a-f0-9]{40}}i', $identifier) && ($res = $this->cache->read($identifier))) { $this->infoCache[$identifier] = JsonFile::parseJson($res); } if (!isset($this->infoCache[$identifier])) { $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' . $this->owner . '/' . $this->repository . '/src/' . $identifier . '/composer.json'; $file = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource); if (!is_array($file) || !array_key_exists('data', $file)) { return array(); } $composer = JsonFile::parseJson($file['data'], $resource); if (empty($composer['time'])) { $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' . $this->owner . '/' . $this->repository . '/changesets/' . $identifier; $changeset = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource); $composer['time'] = $changeset['timestamp']; } if (!isset($composer['support']['source'])) { $label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier; if (array_key_exists($label, $tags = $this->getTags())) { $hash = $tags[$label]; } elseif (array_key_exists($label, $branches = $this->getBranches())) { $hash = $branches[$label]; } if (!isset($hash)) { $composer['support']['source'] = sprintf('https://%s/%s/%s/src', $this->originUrl, $this->owner, $this->repository); } else { $composer['support']['source'] = sprintf('https://%s/%s/%s/src/%s/?at=%s', $this->originUrl, $this->owner, $this->repository, $hash, $label); } } if (!isset($composer['support']['issues']) && $this->hasIssues) { $composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository); } if (preg_match('{[a-f0-9]{40}}i', $identifier)) { $this->cache->write($identifier, json_encode($composer)); } $this->infoCache[$identifier] = $composer; } return $this->infoCache[$identifier]; }
/** * {@inheritDoc} */ public function getComposerInformation($identifier) { $identifier = '/' . trim($identifier, '/') . '/'; if ($res = $this->cache->read($identifier . '.json')) { $this->infoCache[$identifier] = JsonFile::parseJson($res); } if (!isset($this->infoCache[$identifier])) { preg_match('{^(.+?)(@\\d+)?/$}', $identifier, $match); if (!empty($match[2])) { $path = $match[1]; $rev = $match[2]; } else { $path = $identifier; $rev = ''; } try { $resource = $path . 'composer.json'; $output = $this->execute('svn cat', $this->baseUrl . $resource . $rev); if (!trim($output)) { return; } } catch (\RuntimeException $e) { throw new TransportException($e->getMessage()); } $composer = JsonFile::parseJson($output, $this->baseUrl . $resource . $rev); if (!isset($composer['time'])) { $output = $this->execute('svn info', $this->baseUrl . $path . $rev); foreach ($this->process->splitLines($output) as $line) { if ($line && preg_match('{^Last Changed Date: ([^(]+)}', $line, $match)) { $date = new \DateTime($match[1], new \DateTimeZone('UTC')); $composer['time'] = $date->format('Y-m-d H:i:s'); break; } } } $this->cache->write($identifier . '.json', json_encode($composer)); $this->infoCache[$identifier] = $composer; } return $this->infoCache[$identifier]; }
/** * Use the 'newest' themes feed as a form of cache invalidation. */ function cache($providerHash, Cache $cache) { // get the X newest plugins $request = ['browse' => 'new', 'per_page' => self::newestNum, 'fields' => ['name' => false, 'version' => false, 'rating' => false, 'downloaded' => false, 'downloadlink' => false, 'last_updated' => false, 'homepage' => false, 'tags' => false, 'template' => false, 'screenshot_url' => false, 'preview_url' => false, 'author' => false, 'description' => false]]; try { $response = $this->queryAPI('query_themes', $request); } catch (RuntimeException $e) { if ($this->io->isVerbose()) { $this->io->writeError($e->getMessage()); } // invalidate the cache return false; } $newest = []; if (!empty($response['themes']) && is_array($response['themes'])) { foreach ($response['themes'] as $theme) { $newest[] = $theme['slug']; } } // do we even have a provider list and old set of newest to work off of? if (is_array($providerHash) && ($lastNewest = $cache->read('newest.json'))) { // the newest from the last time we checked if ($lastNewest = json_decode($lastNewest)) { $newProviders = array_diff($newest, $lastNewest); // if the number of new providers is equal to number we pulled, assume there may be more and invalidate the cache if (count($newProviders) < self::newestNum) { $url = reset($this->config['url']); foreach ($newProviders as $name) { // full path to this provider in the SVN repo, no trailing slash $providerHash[$name] = "{$url}/{$name}"; } } else { $providerHash = false; } } else { $providerHash = false; } } // save the newest plugins to the cache $cache->write('newest.json', json_encode($newest)); return $providerHash; }