1
0
Fork 0

Merge branch '1.6'

pull/7331/merge
Jordi Boggiano 2018-05-15 16:07:05 +02:00
commit 46f973e213
3 changed files with 105 additions and 6 deletions

View File

@ -388,6 +388,7 @@ EOF;
public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
{
$mainPackageMap = array_shift($packageMap);
$packageMap = $this->filterPackageMap($packageMap, $mainPackage);
$sortedPackageMap = $this->sortPackageMap($packageMap);
$sortedPackageMap[] = $mainPackageMap;
array_unshift($packageMap, $mainPackageMap);
@ -899,6 +900,48 @@ INITIALIZER;
return md5($package->getName() . ':' . $path);
}
/**
* Filters out dev-dependencies when not in dev-mode
*
* @param array $packageMap
* @param PackageInterface $mainPackage
* @return array
*/
protected function filterPackageMap(array $packageMap, PackageInterface $mainPackage) {
if ($this->devMode === true) {
return $packageMap;
}
$packages = array();
$include = array();
foreach ($packageMap as $item) {
$package = $item[0];
$name = $package->getName();
$packages[$name] = $package;
}
$add = function (PackageInterface $package) use (&$add, $mainPackage, $packages, &$include) {
foreach ($package->getRequires() as $link) {
$target = $link->getTarget();
$include[$target] = true;
if (isset($packages[$target])) {
$add($packages[$target]);
}
}
};
$add($mainPackage);
return array_filter(
$packageMap,
function ($item) use ($include) {
$package = $item[0];
$name = $package->getName();
return isset($include[$name]);
}
);
}
/**
* Sorts packages by dependency weight
*

View File

@ -201,9 +201,21 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$hostname = parse_url($url, PHP_URL_HOST) ?: $url;
$json = $this->rfs->getContents($hostname, $url, false);
$results = JsonFile::parseJson($json, $url);
$search = JsonFile::parseJson($json, $url);
return $results['results'];
if (empty($search['results'])) {
return array();
}
$results = array();
foreach ($search['results'] as $result) {
// do not show virtual packages in results as they are not directly useful from a composer perspective
if (empty($result['virtual'])) {
$results[] = $result;
}
}
return $results;
}
if ($this->hasProviders()) {

View File

@ -360,6 +360,10 @@ class AutoloadGeneratorTest extends TestCase
public function testVendorsAutoloading()
{
$package = new Package('a', '1.0', '1.0');
$package->setRequires(array(
new Link('a', 'a/a'),
new Link('a', 'b/b')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -406,6 +410,10 @@ class AutoloadGeneratorTest extends TestCase
public function testVendorsClassMapAutoloading()
{
$package = new Package('a', '1.0', '1.0');
$package->setRequires(array(
new Link('a', 'a/a'),
new Link('a', 'b/b')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -441,6 +449,10 @@ class AutoloadGeneratorTest extends TestCase
public function testVendorsClassMapAutoloadingWithTargetDir()
{
$package = new Package('a', '1.0', '1.0');
$package->setRequires(array(
new Link('a', 'a/a'),
new Link('a', 'b/b')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -476,6 +488,11 @@ class AutoloadGeneratorTest extends TestCase
public function testClassMapAutoloadingEmptyDirAndExactFile()
{
$package = new Package('a', '1.0', '1.0');
$package->setRequires(array(
new Link('a', 'a/a'),
new Link('a', 'b/b'),
new Link('a', 'c/c')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -515,6 +532,11 @@ class AutoloadGeneratorTest extends TestCase
public function testClassMapAutoloadingAuthoritativeAndApcu()
{
$package = new Package('a', '1.0', '1.0');
$package->setRequires(array(
new Link('a', 'a/a'),
new Link('a', 'b/b'),
new Link('a', 'c/c')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -559,6 +581,11 @@ class AutoloadGeneratorTest extends TestCase
{
$package = new Package('a', '1.0', '1.0');
$package->setAutoload(array('files' => array('root.php')));
$package->setRequires(array(
new Link('a', 'a/a'),
new Link('a', 'b/b'),
new Link('a', 'c/c')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -604,6 +631,14 @@ class AutoloadGeneratorTest extends TestCase
$notAutoloadPackage = new Package('a', '1.0', '1.0');
$requires = array(
new Link('a', 'a/a'),
new Link('a', 'b/b'),
new Link('a', 'c/c')
);
$autoloadPackage->setRequires($requires);
$notAutoloadPackage->setRequires($requires);
$autoloadPackages = array();
$autoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
$autoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
@ -667,9 +702,12 @@ class AutoloadGeneratorTest extends TestCase
{
$package = new Package('a', '1.0', '1.0');
$package->setAutoload(array('files' => array('root2.php')));
$package->setRequires(array(new Link('a', 'z/foo')));
$package->setRequires(array(new Link('a', 'd/d')));
$package->setRequires(array(new Link('a', 'e/e')));
$package->setRequires(array(
new Link('a', 'z/foo'),
new Link('a', 'b/bar'),
new Link('a', 'd/d'),
new Link('a', 'e/e')
));
$packages = array();
$packages[] = $z = new Package('z/foo', '1.0', '1.0');
@ -736,7 +774,10 @@ class AutoloadGeneratorTest extends TestCase
'psr-0' => array('A\\B' => $this->workingDir.'/lib'),
'classmap' => array($this->workingDir.'/src'),
));
$mainPackage->setRequires(array(new Link('z', 'a/a')));
$mainPackage->setRequires(array(
new Link('z', 'a/a'),
new Link('z', 'b/b')
));
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
@ -993,6 +1034,9 @@ EOF;
'classmap' => array('classmap'),
'files' => array('test.php'),
));
$package->setRequires(array(
new Link('a', 'b/b')
));
$vendorPackage = new Package('b/b', '1.0', '1.0');
$vendorPackage->setAutoload(array(