Allow the use of self.version in package links

main
Jordi Boggiano 13 years ago
parent 22858e81ef
commit e340022cce

@ -140,7 +140,7 @@ class ArrayLoader
if (isset($config[$type])) {
$method = 'set'.ucfirst($description);
$package->{$method}(
$this->loadLinksFromConfig($package->getName(), $description, $config[$type])
$this->loadLinksFromConfig($package, $description, $config[$type])
);
}
}
@ -152,12 +152,15 @@ class ArrayLoader
return $package;
}
private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs)
private function loadLinksFromConfig($package, $description, array $linksSpecs)
{
$links = array();
foreach ($linksSpecs as $packageName => $constraint) {
if ('self.version' === $constraint) {
$constraint = $package->getVersion();
}
$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;

@ -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());
}
}
Loading…
Cancel
Save