Add loadAliasPackage to the StreamableRepositoryInterface and clear up responsibilities between Pool and Repositories
parent
9a1fd450b0
commit
e46d26cb9b
|
@ -44,13 +44,11 @@ class Pool
|
|||
protected $packageByName = array();
|
||||
protected $acceptableStabilities;
|
||||
protected $stabilityFlags;
|
||||
protected $loader;
|
||||
protected $versionParser;
|
||||
|
||||
public function __construct($minimumStability = 'stable', array $stabilityFlags = array())
|
||||
{
|
||||
$stabilities = BasePackage::$stabilities;
|
||||
$this->loader = new ArrayLoader;
|
||||
$this->versionParser = new VersionParser;
|
||||
$this->acceptableStabilities = array();
|
||||
foreach (BasePackage::$stabilities as $stability => $value) {
|
||||
|
@ -313,19 +311,15 @@ class Pool
|
|||
{
|
||||
if (is_array($data)) {
|
||||
if (isset($data['alias_of'])) {
|
||||
// TODO move to $repo->loadAliasPackage?
|
||||
$aliasOf = $this->packageById($data['alias_of']);
|
||||
$rootAlias = !empty($data['root_alias']);
|
||||
$package = $this->packages[$data['id'] - 1] = new AliasPackage($aliasOf, $data['version'], $data['alias']);
|
||||
$package->setId($data['id']);
|
||||
$package->setRootPackageAlias($rootAlias);
|
||||
|
||||
return $package;
|
||||
$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);
|
||||
}
|
||||
|
||||
$package = $this->packages[$data['id'] - 1] = $data['repo']->loadPackage($data, $data['id']);
|
||||
|
||||
return $package;
|
||||
$package->setId($data['id']);
|
||||
$data = $package;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
@ -342,6 +336,7 @@ class Pool
|
|||
*/
|
||||
private function match($candidate, $name, LinkConstraintInterface $constraint)
|
||||
{
|
||||
// handle array packages
|
||||
if (is_array($candidate)) {
|
||||
$candidateName = $candidate['name'];
|
||||
$candidateVersion = $candidate['version'];
|
||||
|
@ -357,6 +352,7 @@ class Pool
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// handle object packages
|
||||
$candidateName = $candidate->getName();
|
||||
$candidateVersion = $candidate->getVersion();
|
||||
$provides = $candidate->getProvides();
|
||||
|
@ -381,5 +377,4 @@ class Pool
|
|||
|
||||
return self::MATCH_NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,6 +81,9 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository
|
|||
@file_get_contents($url, false, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMinimalPackages()
|
||||
{
|
||||
if (isset($this->minimalPackages)) {
|
||||
|
@ -119,15 +122,31 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository
|
|||
return $this->minimalPackages;
|
||||
}
|
||||
|
||||
public function loadPackage(array $data, $id)
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function loadPackage(array $data)
|
||||
{
|
||||
$package = $this->loader->load($data['raw']);
|
||||
$package->setId($id);
|
||||
$package->setRepository($this);
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function loadAliasPackage(array $data, PackageInterface $aliasOf)
|
||||
{
|
||||
$aliasPackage = $this->createAliasPackage($aliasOf, $data['version'], $data['alias']);
|
||||
$aliasPackage->setRepository($this);
|
||||
|
||||
return $aliasPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Repository;
|
||||
|
||||
use Composer\Package\AliasPackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
|
@ -22,9 +23,33 @@ interface StreamableRepositoryInterface extends RepositoryInterface
|
|||
/**
|
||||
* Return partial package data without loading them all to save on memory
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMinimalPackages();
|
||||
|
||||
public function loadPackage(array $data, $id);
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue