Merge remote-tracking branch 'hason/vendordir'

main
Jordi Boggiano 12 years ago
commit cdfcaface4

@ -18,6 +18,7 @@ use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Operation\InstallOperation; use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\Util\Filesystem;
/** /**
* Package operation manager. * Package operation manager.
@ -39,13 +40,15 @@ class InstallationManager
*/ */
public function __construct($vendorDir = 'vendor') public function __construct($vendorDir = 'vendor')
{ {
if (substr($vendorDir, 0, 1) === '/' || substr($vendorDir, 1, 1) === ':') { $fs = new Filesystem();
if ($fs->isAbsolutePath($vendorDir)) {
$basePath = getcwd(); $basePath = getcwd();
if (0 !== strpos($vendorDir, $basePath)) { $relativePath = $fs->findShortestPath($basePath.'/file', $vendorDir);
throw new \InvalidArgumentException("Vendor dir ($vendorDir) must be within the current working directory ($basePath)."); if ($fs->isAbsolutePath($relativePath)) {
throw new \InvalidArgumentException("Vendor dir ($vendorDir) must be accessible from the directory ($basePath).");
} }
// convert to relative path $this->vendorPath = $relativePath;
$this->vendorPath = rtrim(substr($vendorDir, strlen($basePath)+1), '/');
} else { } else {
$this->vendorPath = rtrim($vendorDir, '/'); $this->vendorPath = rtrim($vendorDir, '/');
} }
@ -203,4 +206,4 @@ class InstallationManager
return getcwd().DIRECTORY_SEPARATOR.$this->vendorPath; return getcwd().DIRECTORY_SEPARATOR.$this->vendorPath;
} }
} }

@ -19,6 +19,21 @@ use Composer\DependencyResolver\Operation\UninstallOperation;
class InstallationManagerTest extends \PHPUnit_Framework_TestCase class InstallationManagerTest extends \PHPUnit_Framework_TestCase
{ {
public function testVendorDirOutsideTheWorkingDir()
{
$manager = new InstallationManager(realpath(getcwd().'/../'));
$this->assertSame('../', $manager->getVendorPath());
}
/**
* @expectedException InvalidArgumentException
*/
public function testVendorDirNotAccessible()
{
$manager = new InstallationManager('/oops');
$this->assertSame('../', $manager->getVendorPath());
}
public function testAddGetInstaller() public function testAddGetInstaller()
{ {
$installer = $this->createInstallerMock(); $installer = $this->createInstallerMock();

Loading…
Cancel
Save