|
@@ -43,9 +43,10 @@ class ComposerRepository extends ArrayRepository
|
|
|
protected $searchUrl;
|
|
|
protected $hasProviders = false;
|
|
|
protected $providersUrl;
|
|
|
- protected $loadedMap = array();
|
|
|
protected $lazyProvidersUrl;
|
|
|
protected $providerListing;
|
|
|
+ protected $providers = array();
|
|
|
+ protected $providersByUid = array();
|
|
|
protected $loader;
|
|
|
protected $rootAliases;
|
|
|
protected $allowSslDowngrade = false;
|
|
@@ -95,51 +96,6 @@ class ComposerRepository extends ArrayRepository
|
|
|
$this->rootAliases = $rootAliases;
|
|
|
}
|
|
|
|
|
|
- public function getRootAliases()
|
|
|
- {
|
|
|
- return $this->rootAliases;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load all packages with given names and dependencies
|
|
|
- *
|
|
|
- * @param array $packageNames
|
|
|
- * @param callable|null $acceptableCallback Callback to filter packages
|
|
|
- *
|
|
|
- * @return array The loaded package objects
|
|
|
- */
|
|
|
- public function loadRecursively(array $packageNames, $acceptableCallback)
|
|
|
- {
|
|
|
- $workQueue = new \SplQueue;
|
|
|
-
|
|
|
- foreach ($packageNames as $packageName) {
|
|
|
- $workQueue->enqueue($packageName);
|
|
|
- }
|
|
|
-
|
|
|
- $loadedPackages = array();
|
|
|
-
|
|
|
- while (!$workQueue->isEmpty()) {
|
|
|
- $packageName = $workQueue->dequeue();
|
|
|
- if (isset($this->loadedMap[$packageName])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $this->loadedMap[$packageName] = true;
|
|
|
-
|
|
|
- $packages = $this->loadName($packageName, $acceptableCallback);
|
|
|
-
|
|
|
- foreach ($packages as $package) {
|
|
|
- $loadedPackages[] = $package;
|
|
|
- $requires = $package->getRequires();
|
|
|
- foreach ($requires as $link) {
|
|
|
- $workQueue->enqueue($link->getTarget());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $loadedPackages;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* {@inheritDoc}
|
|
|
*/
|
|
@@ -155,7 +111,7 @@ class ComposerRepository extends ArrayRepository
|
|
|
|
|
|
foreach ($this->getProviderNames() as $providerName) {
|
|
|
if ($name === $providerName) {
|
|
|
- $packages = $this->loadName($providerName, null, false);
|
|
|
+ $packages = $this->whatProvides(new Pool('dev'), $providerName);
|
|
|
foreach ($packages as $package) {
|
|
|
if ($name == $package->getName() && $version === $package->getVersion()) {
|
|
|
return $package;
|
|
@@ -186,7 +142,7 @@ class ComposerRepository extends ArrayRepository
|
|
|
|
|
|
foreach ($this->getProviderNames() as $providerName) {
|
|
|
if ($name === $providerName) {
|
|
|
- $packages = $this->loadName($providerName, null, false);
|
|
|
+ $packages = $this->whatProvides(new Pool('dev'), $providerName);
|
|
|
foreach ($packages as $package) {
|
|
|
if ($name == $package->getName() && (null === $version || $version === $package->getVersion())) {
|
|
|
$packages[] = $package;
|
|
@@ -284,17 +240,22 @@ class ComposerRepository extends ArrayRepository
|
|
|
return $this->hasProviders;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Loads package data for a given package name or provider name
|
|
|
- *
|
|
|
- * @param string $name
|
|
|
- * @param callable|null $acceptableCallback A callback to check if a package should be loaded
|
|
|
- * @param bool $exactMatch Whether packages only providing the name should be ignored
|
|
|
- *
|
|
|
- * @return array All packages that were loaded
|
|
|
- */
|
|
|
- protected function loadName($name, $acceptableCallback, $exactMatch = true)
|
|
|
+ public function resetPackageIds()
|
|
|
+ {
|
|
|
+ foreach ($this->providersByUid as $package) {
|
|
|
+ if ($package instanceof AliasPackage) {
|
|
|
+ $package->getAliasOf()->setId(-1);
|
|
|
+ }
|
|
|
+ $package->setId(-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
@@ -335,32 +296,69 @@ class ComposerRepository extends ArrayRepository
|
|
|
$packages = $this->fetchFile($url, $cacheKey, $hash);
|
|
|
}
|
|
|
|
|
|
- $loadedPackages = array();
|
|
|
- foreach ($packages['packages'] as $packageName => $versions) {
|
|
|
- if ($exactMatch && $packageName !== $name) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
+ $this->providers[$name] = array();
|
|
|
+ foreach ($packages['packages'] as $versions) {
|
|
|
foreach ($versions as $version) {
|
|
|
- if ($acceptableCallback && !call_user_func(
|
|
|
- $acceptableCallback, strtolower($version['name']), VersionParser::parseStability($version['version'])
|
|
|
- )) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // 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);
|
|
|
|
|
|
- // load acceptable packages in the providers
|
|
|
- $package = $this->createPackage($version, 'Composer\Package\Package');
|
|
|
- $this->addPackage($package);
|
|
|
+ $this->providers[$name][$version['uid']] = $aliased;
|
|
|
+ $this->providers[$name][$version['uid'].'-alias'] = $package;
|
|
|
|
|
|
- $loadedPackages[] = $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);
|
|
|
|
|
|
- if ($package instanceof AliasPackage) {
|
|
|
- $loadedPackages[] = $package->getAliasOf();
|
|
|
+ $this->providers[$name][$version['uid'].'-root'] = $alias;
|
|
|
+ $this->providersByUid[$version['uid'].'-root'] = $alias;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $loadedPackages;
|
|
|
+ return $this->providers[$name];
|
|
|
}
|
|
|
|
|
|
/**
|