1
0
Fork 0

Merge pull request #3447 from naderman/remove-streamable-repository

This entirely removes StreamableRepositories and minimal package arrays
pull/3264/head
Nils Adermann 2014-11-20 18:12:10 +01:00
commit b8aead09ed
3 changed files with 13 additions and 257 deletions

View File

@ -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];
}
/**
@ -291,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;
}
@ -307,15 +232,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 +301,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
@ -409,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;
}
if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) {
$requireFilter = $this->filterRequires[$name];
@ -439,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();
}
// aliases create multiple replaces/provides for one target so they can not use the shortcut below
if (isset($replaces[0]) || isset($provides[0])) {

View File

@ -30,7 +30,7 @@ use Composer\EventDispatcher\EventDispatcher;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
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();

View File

@ -1,61 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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 <j.boggiano@seld.be>
*/
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);
}