From 89bd9be295376e450e388bee68a17ffbbeba0cad Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 20 Nov 2014 17:23:51 +0100 Subject: [PATCH 1/2] This entirely removes StreamableRepositories and minimal package arrays --- src/Composer/DependencyResolver/Pool.php | 104 +----------------- .../Repository/ComposerRepository.php | 70 +----------- .../StreamableRepositoryInterface.php | 61 ---------- 3 files changed, 5 insertions(+), 230 deletions(-) delete mode 100644 src/Composer/Repository/StreamableRepositoryInterface.php diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 8182819eb..56ee1f23c 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -22,7 +22,6 @@ use Composer\Repository\RepositoryInterface; use Composer\Repository\CompositeRepository; use Composer\Repository\ComposerRepository; use Composer\Repository\InstalledRepositoryInterface; -use Composer\Repository\StreamableRepositoryInterface; use Composer\Repository\PlatformRepository; use Composer\Package\PackageInterface; @@ -97,79 +96,6 @@ class Pool $this->providerRepos[] = $repo; $repo->setRootAliases($rootAliases); $repo->resetPackageIds(); - } elseif ($repo instanceof StreamableRepositoryInterface) { - foreach ($repo->getMinimalPackages() as $package) { - $name = $package['name']; - $version = $package['version']; - $stability = VersionParser::parseStability($version); - - // collect names - $names = array( - $name => true, - ); - if (isset($package['provide'])) { - foreach ($package['provide'] as $target => $constraint) { - $names[$target] = true; - } - } - if (isset($package['replace'])) { - foreach ($package['replace'] as $target => $constraint) { - $names[$target] = true; - } - } - $names = array_keys($names); - - if ($exempt || $this->isPackageAcceptable($names, $stability)) { - $package['id'] = $this->id++; - $package['stability'] = $stability; - $this->packages[] = $package; - $this->packageByExactName[$name][$package['id']] = $this->packages[$this->id - 2]; - - foreach ($names as $provided) { - $this->packageByName[$provided][$package['id']] = $this->packages[$this->id - 2]; - } - - // handle root package aliases - unset($rootAliasData); - if (isset($rootAliases[$name][$version])) { - $rootAliasData = $rootAliases[$name][$version]; - } elseif (isset($package['alias_normalized']) && isset($rootAliases[$name][$package['alias_normalized']])) { - $rootAliasData = $rootAliases[$name][$package['alias_normalized']]; - } - - if (isset($rootAliasData)) { - $alias = $package; - unset($alias['raw']); - $alias['version'] = $rootAliasData['alias_normalized']; - $alias['alias'] = $rootAliasData['alias']; - $alias['alias_of'] = $package['id']; - $alias['id'] = $this->id++; - $alias['root_alias'] = true; - $this->packages[] = $alias; - $this->packageByExactName[$name][$alias['id']] = $this->packages[$this->id - 2]; - - foreach ($names as $provided) { - $this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2]; - } - } - - // handle normal package aliases - if (isset($package['alias'])) { - $alias = $package; - unset($alias['raw']); - $alias['version'] = $package['alias_normalized']; - $alias['alias'] = $package['alias']; - $alias['alias_of'] = $package['id']; - $alias['id'] = $this->id++; - $this->packages[] = $alias; - $this->packageByExactName[$name][$alias['id']] = $this->packages[$this->id - 2]; - - foreach ($names as $provided) { - $this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2]; - } - } - } - } } else { foreach ($repo->getPackages() as $package) { $names = $package->getNames(); @@ -227,7 +153,7 @@ class Pool */ public function packageById($id) { - return $this->ensurePackageIsLoaded($this->packages[$id - 1]); + return $this->packages[$id - 1]; } /** @@ -307,15 +233,15 @@ class Pool case self::MATCH: $nameMatch = true; - $matches[] = $this->ensurePackageIsLoaded($candidate); + $matches[] = $candidate; break; case self::MATCH_PROVIDE: - $provideMatches[] = $this->ensurePackageIsLoaded($candidate); + $provideMatches[] = $candidate; break; case self::MATCH_REPLACE: - $matches[] = $this->ensurePackageIsLoaded($candidate); + $matches[] = $candidate; break; case self::MATCH_FILTERED: @@ -376,28 +302,6 @@ class Pool return false; } - private function ensurePackageIsLoaded($data) - { - if (is_array($data)) { - if (isset($data['alias_of'])) { - $aliasOf = $this->packageById($data['alias_of']); - $package = $this->packages[$data['id'] - 1] = $data['repo']->loadAliasPackage($data, $aliasOf); - $package->setRootPackageAlias(!empty($data['root_alias'])); - } else { - $package = $this->packages[$data['id'] - 1] = $data['repo']->loadPackage($data); - } - - foreach ($package->getNames() as $name) { - $this->packageByName[$name][$data['id']] = $package; - } - $package->setId($data['id']); - - return $package; - } - - return $data; - } - /** * Checks if the package matches the given constraint directly or through * provided or replaced packages diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 4bfe6db4e..459fa55a7 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -30,7 +30,7 @@ use Composer\EventDispatcher\EventDispatcher; /** * @author Jordi Boggiano */ -class ComposerRepository extends ArrayRepository implements StreamableRepositoryInterface +class ComposerRepository extends ArrayRepository { protected $config; protected $options; @@ -165,49 +165,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository return parent::getPackages(); } - /** - * {@inheritDoc} - */ - public function getMinimalPackages() - { - if (isset($this->minimalPackages)) { - return $this->minimalPackages; - } - - if (null === $this->rawData) { - $this->rawData = $this->loadDataFromServer(); - } - - $this->minimalPackages = array(); - $versionParser = new VersionParser; - - foreach ($this->rawData as $package) { - $version = !empty($package['version_normalized']) ? $package['version_normalized'] : $versionParser->normalize($package['version']); - $data = array( - 'name' => strtolower($package['name']), - 'repo' => $this, - 'version' => $version, - 'raw' => $package, - ); - if (!empty($package['replace'])) { - $data['replace'] = $package['replace']; - } - if (!empty($package['provide'])) { - $data['provide'] = $package['provide']; - } - - // add branch aliases - if ($aliasNormalized = $this->loader->getBranchAlias($package)) { - $data['alias'] = preg_replace('{(\.9{7})+}', '.x', $aliasNormalized); - $data['alias_normalized'] = $aliasNormalized; - } - - $this->minimalPackages[] = $data; - } - - return $this->minimalPackages; - } - /** * {@inheritDoc} */ @@ -262,20 +219,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository return $providers; } - /** - * {@inheritDoc} - */ - public function loadPackage(array $data) - { - $package = $this->createPackage($data['raw'], 'Composer\Package\Package'); - if ($package instanceof AliasPackage) { - $package = $package->getAliasOf(); - } - $package->setRepository($this); - - return $package; - } - protected function configurePackageTransportOptions(PackageInterface $package) { foreach ($package->getDistUrls() as $url) { @@ -287,17 +230,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository } } - /** - * {@inheritDoc} - */ - public function loadAliasPackage(array $data, PackageInterface $aliasOf) - { - $aliasPackage = $this->createAliasPackage($aliasOf, $data['version'], $data['alias']); - $aliasPackage->setRepository($this); - - return $aliasPackage; - } - public function hasProviders() { $this->loadRootServerFile(); diff --git a/src/Composer/Repository/StreamableRepositoryInterface.php b/src/Composer/Repository/StreamableRepositoryInterface.php deleted file mode 100644 index f5c694642..000000000 --- a/src/Composer/Repository/StreamableRepositoryInterface.php +++ /dev/null @@ -1,61 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Repository; - -use Composer\Package\AliasPackage; -use Composer\Package\PackageInterface; - -/** - * @author Jordi Boggiano - */ -interface StreamableRepositoryInterface extends RepositoryInterface -{ - /** - * Return partial package data without loading them all to save on memory - * - * The function must return an array of package arrays. - * - * The package array must contain the following fields: - * - name: package name (normalized/lowercased) - * - repo: reference to the repository instance - * - version: normalized version - * - replace: array of package name => version constraint, optional - * - provide: array of package name => version constraint, optional - * - alias: pretty alias that this package should be aliased to, optional - * - alias_normalized: normalized alias that this package should be aliased to, optional - * - * Any additional information can be returned and will be sent back - * into loadPackage/loadAliasPackage for completing the package loading - * when it's needed. - * - * @return array - */ - public function getMinimalPackages(); - - /** - * Loads a package from minimal info of the package - * - * @param array $data the minimal info as was returned by getMinimalPackage - * @return PackageInterface - */ - public function loadPackage(array $data); - - /** - * Loads an alias package from minimal info of the package - * - * @param array $data the minimal info as was returned by getMinimalPackage - * @param PackageInterface $aliasOf the package which this alias is an alias of - * @return AliasPackage - */ - public function loadAliasPackage(array $data, PackageInterface $aliasOf); -} From dccb728e1050a5a4530f28f342d266924a7271bb Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 20 Nov 2014 17:42:05 +0100 Subject: [PATCH 2/2] Remove further unnecessary checks for packages being arrays --- src/Composer/DependencyResolver/Pool.php | 35 ++++++------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index 56ee1f23c..98553abc4 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -217,9 +217,8 @@ class Pool } if ($this->whitelist !== null && ( - (is_array($candidate) && isset($candidate['id']) && !isset($this->whitelist[$candidate['id']])) || - (is_object($candidate) && !($candidate instanceof AliasPackage) && !isset($this->whitelist[$candidate->getId()])) || - (is_object($candidate) && $candidate instanceof AliasPackage && !isset($this->whitelist[$aliasOfCandidate->getId()])) + (!($candidate instanceof AliasPackage) && !isset($this->whitelist[$candidate->getId()])) || + ($candidate instanceof AliasPackage && !isset($this->whitelist[$aliasOfCandidate->getId()])) )) { continue; } @@ -313,19 +312,10 @@ class Pool */ private function match($candidate, $name, LinkConstraintInterface $constraint = null) { - // handle array packages - if (is_array($candidate)) { - $candidateName = $candidate['name']; - $candidateVersion = $candidate['version']; - $isDev = $candidate['stability'] === 'dev'; - $isAlias = isset($candidate['alias_of']); - } else { - // handle object packages - $candidateName = $candidate->getName(); - $candidateVersion = $candidate->getVersion(); - $isDev = $candidate->getStability() === 'dev'; - $isAlias = $candidate instanceof AliasPackage; - } + $candidateName = $candidate->getName(); + $candidateVersion = $candidate->getVersion(); + $isDev = $candidate->getStability() === 'dev'; + $isAlias = $candidate instanceof AliasPackage; if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) { $requireFilter = $this->filterRequires[$name]; @@ -343,17 +333,8 @@ class Pool return self::MATCH_NAME; } - if (is_array($candidate)) { - $provides = isset($candidate['provide']) - ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'provides', $candidate['provide']) - : array(); - $replaces = isset($candidate['replace']) - ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'replaces', $candidate['replace']) - : array(); - } else { - $provides = $candidate->getProvides(); - $replaces = $candidate->getReplaces(); - } + $provides = $candidate->getProvides(); + $replaces = $candidate->getReplaces(); // aliases create multiple replaces/provides for one target so they can not use the shortcut below if (isset($replaces[0]) || isset($provides[0])) {