コード例 #1
0
 /**
  * @param \Composer\Package\Link $packageLink
  * @param bool $ignoreRequiredVersion
  * @param bool $exactAsTilda
  * @return \Composer\Package\PackageInterface[]
  */
 private function getVersionsByPackageLink(Link $packageLink, $ignoreRequiredVersion = FALSE, $exactAsTilda = FALSE)
 {
     $constraint = $packageLink->getConstraint();
     if ($this->versionParser->parseStability($constraint->getPrettyString()) !== 'dev') {
         if ($ignoreRequiredVersion) {
             $constraint = NULL;
         } elseif ($exactAsTilda && $this->isExact($constraint)) {
             $constraint = $this->versionParser->parseConstraints(sprintf('~%s', $constraint->getPrettyString()));
         }
     }
     return $this->getVersions($packageLink->getTarget(), $constraint);
 }
コード例 #2
0
ファイル: AliasPackage.php プロジェクト: retbrown/composer
 /**
  * All descendants' constructors should call this parent constructor
  *
  * @param PackageInterface $aliasOf       The package this package is an alias of
  * @param string           $version       The version the alias must report
  * @param string           $prettyVersion The alias's non-normalized version
  */
 public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
 {
     parent::__construct($aliasOf->getName());
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->aliasOf = $aliasOf;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
     foreach (array('requires', 'devRequires', 'conflicts', 'provides', 'replaces') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         $this->{$type} = $this->replaceSelfVersionDependencies($links, $type);
     }
 }
コード例 #3
0
ファイル: Version.php プロジェクト: mbrodala/climb
 /**
  * Get the last version number from a list of versions.
  *
  * @param array $versions
  *
  * @return string
  */
 public static function latest(array $versions)
 {
     // Normalize version numbers.
     $versions = array_map(function ($version) {
         return static::normalize($version);
     }, $versions);
     // Get the highest version number.
     $latest = array_reduce($versions, function ($carry, $item) {
         // Skip unstable versions.
         if (VersionParser::parseStability($item) !== 'stable') {
             return $carry;
         }
         return Comparator::greaterThan($carry, $item) ? $carry : $item;
     }, '0.0.0');
     return $latest;
 }
コード例 #4
0
 private function extractReferences(array $requires, array $references)
 {
     foreach ($requires as $reqName => $reqVersion) {
         $reqVersion = preg_replace('{^([^,\\s@]+) as .+$}', '$1', $reqVersion);
         if (preg_match('{^[^,\\s@]+?#([a-f0-9]+)$}', $reqVersion, $match) && 'dev' === ($stabilityName = VersionParser::parseStability($reqVersion))) {
             $name = strtolower($reqName);
             $references[$name] = $match[1];
         }
     }
     return $references;
 }
コード例 #5
0
 public function whatProvides(Pool $pool, $name)
 {
     if (isset($this->providers[$name])) {
         return $this->providers[$name];
     }
     // skip platform packages
     if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name) {
         return array();
     }
     if (null === $this->providerListing) {
         $this->loadProviderListings($this->loadRootServerFile());
     }
     if ($this->lazyProvidersUrl && !isset($this->providerListing[$name])) {
         $hash = null;
         $url = str_replace('%package%', $name, $this->lazyProvidersUrl);
         $cacheKey = false;
     } elseif ($this->providersUrl) {
         // package does not exist in this repo
         if (!isset($this->providerListing[$name])) {
             return array();
         }
         $hash = $this->providerListing[$name]['sha256'];
         $url = str_replace(array('%package%', '%hash%'), array($name, $hash), $this->providersUrl);
         $cacheKey = 'provider-' . strtr($name, '/', '$') . '.json';
     } else {
         // BC handling for old providers-includes
         $url = 'p/' . $name . '.json';
         // package does not exist in this repo
         if (!isset($this->providerListing[$url])) {
             return array();
         }
         $hash = $this->providerListing[$url]['sha256'];
         $cacheKey = null;
     }
     if ($cacheKey && $this->cache->sha256($cacheKey) === $hash) {
         $packages = json_decode($this->cache->read($cacheKey), true);
     } else {
         $packages = $this->fetchFile($url, $cacheKey, $hash);
     }
     $this->providers[$name] = array();
     foreach ($packages['packages'] as $versions) {
         foreach ($versions as $version) {
             // avoid loading the same objects twice
             if (isset($this->providersByUid[$version['uid']])) {
                 // skip if already assigned
                 if (!isset($this->providers[$name][$version['uid']])) {
                     // expand alias in two packages
                     if ($this->providersByUid[$version['uid']] instanceof AliasPackage) {
                         $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']]->getAliasOf();
                         $this->providers[$name][$version['uid'] . '-alias'] = $this->providersByUid[$version['uid']];
                     } else {
                         $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']];
                     }
                     // check for root aliases
                     if (isset($this->providersByUid[$version['uid'] . '-root'])) {
                         $this->providers[$name][$version['uid'] . '-root'] = $this->providersByUid[$version['uid'] . '-root'];
                     }
                 }
             } else {
                 if (!$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) {
                     continue;
                 }
                 // load acceptable packages in the providers
                 $package = $this->createPackage($version, 'Composer\\Package\\Package');
                 $package->setRepository($this);
                 if ($package instanceof AliasPackage) {
                     $aliased = $package->getAliasOf();
                     $aliased->setRepository($this);
                     $this->providers[$name][$version['uid']] = $aliased;
                     $this->providers[$name][$version['uid'] . '-alias'] = $package;
                     // override provider with its alias so it can be expanded in the if block above
                     $this->providersByUid[$version['uid']] = $package;
                 } else {
                     $this->providers[$name][$version['uid']] = $package;
                     $this->providersByUid[$version['uid']] = $package;
                 }
                 // handle root package aliases
                 unset($rootAliasData);
                 if (isset($this->rootAliases[$package->getName()][$package->getVersion()])) {
                     $rootAliasData = $this->rootAliases[$package->getName()][$package->getVersion()];
                 } elseif ($package instanceof AliasPackage && isset($this->rootAliases[$package->getName()][$package->getAliasOf()->getVersion()])) {
                     $rootAliasData = $this->rootAliases[$package->getName()][$package->getAliasOf()->getVersion()];
                 }
                 if (isset($rootAliasData)) {
                     $alias = $this->createAliasPackage($package, $rootAliasData['alias_normalized'], $rootAliasData['alias']);
                     $alias->setRepository($this);
                     $this->providers[$name][$version['uid'] . '-root'] = $alias;
                     $this->providersByUid[$version['uid'] . '-root'] = $alias;
                 }
             }
         }
     }
     return $this->providers[$name];
 }
コード例 #6
0
ファイル: Package.php プロジェクト: andy-b-84/composer
 /**
  * Replaces current version and pretty version with passed values.
  * It also sets stability.
  *
  * @param string $version       The package's normalized version
  * @param string $prettyVersion The package's non-normalized version
  */
 public function replaceVersion($version, $prettyVersion)
 {
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
 }
コード例 #7
0
ファイル: SVNRepository.php プロジェクト: balbuf/composer-wp
 public function whatProvides(Pool $pool, $name, $bypassFilters = false)
 {
     // split on vendor and name
     if (count($parts = explode('/', $name)) !== 2) {
         return [];
     }
     list($vendor, $shortName) = $parts;
     // does the vendor match one of our virtual vendors?
     if (!isset($this->vendors[$vendor])) {
         return [];
     }
     // do we already have its packages?
     if (isset($this->providers[$name])) {
         return $this->providers[$name];
     }
     // make sure the providers have been loaded
     $this->loadProviders();
     // does the shortname even exist in this repo?
     if (!isset($this->providerHash[$shortName])) {
         return [];
     }
     // base url for the requested set of packages (i.e. the provider)
     // there should be no trailing slash
     $providerUrl = $this->providerHash[$shortName];
     $packages = [];
     // get a listing of available packages
     // these are paths under the provider url where we should find actual packages
     foreach ((array) $this->repoConfig->get('package-paths') as $path) {
         // the relative path without surrounding slashes
         $relPath = trim($path, '/');
         // if the path ends with a slash, we grab its subdirectories
         if (substr($path, -1) === '/') {
             // try to fetch the packages!
             try {
                 if ($this->io->isVerbose()) {
                     $this->io->writeError("Fetching available versions for {$name}");
                 }
                 $pkgRaw = $this->svnUtil->execute('ls', "{$providerUrl}/{$relPath}");
             } catch (\RuntimeException $e) {
                 // @todo maybe don't throw an exception and just pass this one up?
                 throw new \RuntimeException("SVN Error: Could not retrieve package listing for {$name}. " . $e->getMessage());
             }
             // check the versions and add any good ones to the set
             foreach (SvnUtil::parseSvnList($pkgRaw) as $version) {
                 // format the version identifier to be composer-compatible
                 $version = Util::fixVersion($version, 'dev-default');
                 $version = Util::callFilter($this->repoConfig->get('version-filter'), $version, $name, $path, $providerUrl);
                 // if the version string is empty, we don't take it
                 if (!empty($version)) {
                     $packages[$version] = trim("{$relPath}/{$version}", '/');
                 }
             }
         } else {
             // otherwise we add as-is (no checking is performed to see if this reference really exists)
             // @todo: perhaps add an optional check?
             $version = Util::fixVersion(basename($path), 'dev-default');
             $version = Util::callFilter($this->repoConfig->get('version-filter'), $version, $name, $path, $providerUrl);
             // if the version string is empty, we don't take it
             if (!empty($version)) {
                 $packages[$version] = $relPath;
             }
         }
     }
     // store the providers based on its full name (i.e. with vendor)
     // this allows the same package to be loaded as different types,
     // which allows the package type to be changed in composer.json,
     // i.e. the type that is being removed AND the type that is being installed
     // both have to exist during the solving
     $this->providers[$name] = [];
     // create a package for each tag
     foreach ($packages as $version => $reference) {
         if (!$pool->isPackageAcceptable($shortName, VersionParser::parseStability($version))) {
             continue;
         }
         // first, setup the repo-determined package properties
         $data = ['name' => $name, 'version' => $version, 'type' => $this->vendors[$vendor], 'source' => ['type' => 'svn', 'url' => "{$providerUrl}/", 'reference' => $reference ?: '/']];
         // next, fill in any defaults that were missing
         if (($defaults = $this->repoConfig->get('package-defaults')) && is_array($defaults)) {
             $data = array_merge($defaults, $data);
         }
         // finally, apply any overrides
         if (($overrides = $this->repoConfig->get('package-overrides')) && is_array($overrides)) {
             $data = array_replace($data, $overrides);
         }
         // create the package object
         $package = $this->createPackage($data, 'Composer\\Package\\CompletePackage');
         $package->setRepository($this);
         // add "replaces" array for any other vendors that this repository supports
         if (count($this->vendors) > 1) {
             $replaces = [];
             $constraint = new Constraint('=', $package->getVersion());
             foreach ($this->vendors as $vendorName => $type) {
                 // it doesn't replace itself
                 if ($vendorName === $vendor) {
                     continue;
                 }
                 $replaces[] = new Link($package->getName(), "{$vendorName}/{$shortName}", $constraint, "'{$type}' alias for", $package->getPrettyVersion());
             }
             $package->setReplaces($replaces);
         }
         // apply a filter to the package object
         Util::callFilter($this->repoConfig->get('package-filter'), $package);
         // add the package object to the set
         $this->providers[$name][$version] = $package;
         // handle root aliases
         // @todo: not sure if this is correct (this was copped from the parent class)
         if (isset($this->rootAliases[$package->getName()][$package->getVersion()])) {
             $rootAliasData = $this->rootAliases[$package->getName()][$package->getVersion()];
             $alias = $this->createAliasPackage($package, $rootAliasData['alias_normalized'], $rootAliasData['alias']);
             $alias->setRepository($this);
             $this->providers[$name][$version . '-root'] = $alias;
         }
     }
     return $this->providers[$name];
 }