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