commit
bd1c18d934
|
@ -140,7 +140,7 @@ class ArrayLoader
|
||||||
if (isset($config[$type])) {
|
if (isset($config[$type])) {
|
||||||
$method = 'set'.ucfirst($description);
|
$method = 'set'.ucfirst($description);
|
||||||
$package->{$method}(
|
$package->{$method}(
|
||||||
$this->loadLinksFromConfig($package->getName(), $description, $config[$type])
|
$this->loadLinksFromConfig($package, $description, $config[$type])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,12 +152,15 @@ class ArrayLoader
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs)
|
private function loadLinksFromConfig($package, $description, array $linksSpecs)
|
||||||
{
|
{
|
||||||
$links = array();
|
$links = array();
|
||||||
foreach ($linksSpecs as $packageName => $constraint) {
|
foreach ($linksSpecs as $packageName => $constraint) {
|
||||||
|
if ('self.version' === $constraint) {
|
||||||
|
$constraint = $package->getVersion();
|
||||||
|
}
|
||||||
$constraint = $this->versionParser->parseConstraints($constraint);
|
$constraint = $this->versionParser->parseConstraints($constraint);
|
||||||
$links[] = new Package\Link($srcPackageName, $packageName, $constraint, $description, $constraint);
|
$links[] = new Package\Link($package->getName(), $packageName, $constraint, $description, $constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
|
|
|
@ -135,18 +135,30 @@ class VersionParser
|
||||||
// match wildcard constraints
|
// match wildcard constraints
|
||||||
if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $constraint, $matches)) {
|
if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $constraint, $matches)) {
|
||||||
if (isset($matches[3])) {
|
if (isset($matches[3])) {
|
||||||
$lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.0';
|
|
||||||
$highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999';
|
$highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999';
|
||||||
} elseif (isset($matches[2])) {
|
if ($matches[3] === '0') {
|
||||||
$lowVersion = $matches[1] . '.' . $matches[2] . '.0.0';
|
$lowVersion = $matches[1] . '.' . ($matches[2] - 1) . '.9999999.9999999';
|
||||||
$highVersion = $matches[1] . '.' . $matches[2] . '.9999999.9999999';
|
} else {
|
||||||
|
$lowVersion = $matches[1] . '.' . $matches[2] . '.' . ($matches[3] - 1). '.9999999';
|
||||||
|
}
|
||||||
|
} elseif (isset($matches[2])) {
|
||||||
|
$highVersion = $matches[1] . '.' . $matches[2] . '.9999999.9999999';
|
||||||
|
if ($matches[2] === '0') {
|
||||||
|
$lowVersion = ($matches[1] - 1) . '.9999999.9999999.9999999';
|
||||||
|
} else {
|
||||||
|
$lowVersion = $matches[1] . '.' . ($matches[2] - 1) . '.9999999.9999999';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$lowVersion = $matches[1] . '.0.0.0';
|
|
||||||
$highVersion = $matches[1] . '.9999999.9999999.9999999';
|
$highVersion = $matches[1] . '.9999999.9999999.9999999';
|
||||||
|
if ($matches[1] === '0') {
|
||||||
|
return array(new VersionConstraint('<', $highVersion));
|
||||||
|
} else {
|
||||||
|
$lowVersion = ($matches[1] - 1) . '.9999999.9999999.9999999';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
new VersionConstraint('>=', $lowVersion),
|
new VersionConstraint('>', $lowVersion),
|
||||||
new VersionConstraint('<', $highVersion),
|
new VersionConstraint('<', $highVersion),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?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\Test\Package\Loader;
|
||||||
|
|
||||||
|
use Composer\Package\Loader\ArrayLoader;
|
||||||
|
|
||||||
|
class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->manager = $this->getMock('Composer\Repository\RepositoryManager');
|
||||||
|
$this->loader = new ArrayLoader($this->manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSelfVersion()
|
||||||
|
{
|
||||||
|
$config = array(
|
||||||
|
'name' => 'A',
|
||||||
|
'version' => '1.2.3.4',
|
||||||
|
'replace' => array(
|
||||||
|
'foo' => 'self.version',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
$replaces = $package->getReplaces();
|
||||||
|
$this->assertEquals('== 1.2.3.4', (string) $replaces[0]->getConstraint());
|
||||||
|
}
|
||||||
|
}
|
|
@ -132,7 +132,11 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testParseConstraintsWildcard($input, $min, $max)
|
public function testParseConstraintsWildcard($input, $min, $max)
|
||||||
{
|
{
|
||||||
$parser = new VersionParser;
|
$parser = new VersionParser;
|
||||||
|
if ($min) {
|
||||||
$expected = new MultiConstraint(array($min, $max));
|
$expected = new MultiConstraint(array($min, $max));
|
||||||
|
} else {
|
||||||
|
$expected = $max;
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
$this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
|
||||||
}
|
}
|
||||||
|
@ -140,12 +144,13 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
public function wildcardConstraints()
|
public function wildcardConstraints()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('2.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.9999999.9999999.9999999')),
|
array('2.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.9999999.9999999.9999999')),
|
||||||
array('20.*', new VersionConstraint('>=', '20.0.0.0'), new VersionConstraint('<', '20.9999999.9999999.9999999')),
|
array('20.*', new VersionConstraint('>', '19.9999999.9999999.9999999'), new VersionConstraint('<', '20.9999999.9999999.9999999')),
|
||||||
array('2.0.*', new VersionConstraint('>=', '2.0.0.0'), new VersionConstraint('<', '2.0.9999999.9999999')),
|
array('2.0.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.0.9999999.9999999')),
|
||||||
array('2.2.*', new VersionConstraint('>=', '2.2.0.0'), new VersionConstraint('<', '2.2.9999999.9999999')),
|
array('2.2.*', new VersionConstraint('>', '2.1.9999999.9999999'), new VersionConstraint('<', '2.2.9999999.9999999')),
|
||||||
array('2.10.*', new VersionConstraint('>=', '2.10.0.0'), new VersionConstraint('<', '2.10.9999999.9999999')),
|
array('2.10.*', new VersionConstraint('>', '2.9.9999999.9999999'), new VersionConstraint('<', '2.10.9999999.9999999')),
|
||||||
array('2.1.3.*', new VersionConstraint('>=', '2.1.3.0'), new VersionConstraint('<', '2.1.3.9999999')),
|
array('2.1.3.*', new VersionConstraint('>', '2.1.2.9999999'), new VersionConstraint('<', '2.1.3.9999999')),
|
||||||
|
array('0.*', null, new VersionConstraint('<', '0.9999999.9999999.9999999')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue