Use the config object to define the vendor dir and not the installation manager
parent
fd776853a4
commit
b876dcbafb
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\Installer\InstallationManager;
|
||||
use Composer\Package\AliasPackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
|
@ -24,12 +25,14 @@ use Composer\Util\Filesystem;
|
|||
*/
|
||||
class AutoloadGenerator
|
||||
{
|
||||
public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
|
||||
public function dump(Config $config, RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->ensureDirectoryExists($installationManager->getVendorPath());
|
||||
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
|
||||
$vendorPath = strtr(realpath($config->get('vendor-dir')), '\\', '/');
|
||||
$targetDir = $vendorPath.'/'.$targetDir;
|
||||
$filesystem->ensureDirectoryExists($targetDir);
|
||||
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
|
||||
|
||||
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
|
||||
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
||||
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
|
||||
|
|
|
@ -105,7 +105,7 @@ class Config
|
|||
// convert foo-bar to COMPOSER_FOO_BAR and check if it exists since it overrides the local config
|
||||
$env = 'COMPOSER_' . strtoupper(strtr($key, '-', '_'));
|
||||
|
||||
return $this->process(getenv($env) ?: $this->config[$key]);
|
||||
return rtrim($this->process(getenv($env) ?: $this->config[$key]), '/\\');
|
||||
|
||||
case 'home':
|
||||
return rtrim($this->process($this->config[$key]), '/\\');
|
||||
|
|
|
@ -21,6 +21,7 @@ use Composer\DependencyResolver\Solver;
|
|||
use Composer\DependencyResolver\SolverProblemsException;
|
||||
use Composer\Downloader\DownloadManager;
|
||||
use Composer\Installer\InstallationManager;
|
||||
use Composer\Config;
|
||||
use Composer\Installer\NoopInstaller;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Package\AliasPackage;
|
||||
|
@ -48,6 +49,11 @@ class Installer
|
|||
*/
|
||||
protected $io;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var PackageInterface
|
||||
*/
|
||||
|
@ -105,6 +111,7 @@ class Installer
|
|||
* Constructor
|
||||
*
|
||||
* @param IOInterface $io
|
||||
* @param Config $config
|
||||
* @param PackageInterface $package
|
||||
* @param DownloadManager $downloadManager
|
||||
* @param RepositoryManager $repositoryManager
|
||||
|
@ -113,9 +120,10 @@ class Installer
|
|||
* @param EventDispatcher $eventDispatcher
|
||||
* @param AutoloadGenerator $autoloadGenerator
|
||||
*/
|
||||
public function __construct(IOInterface $io, PackageInterface $package, DownloadManager $downloadManager, RepositoryManager $repositoryManager, Locker $locker, InstallationManager $installationManager, EventDispatcher $eventDispatcher, AutoloadGenerator $autoloadGenerator)
|
||||
public function __construct(IOInterface $io, Config $config, PackageInterface $package, DownloadManager $downloadManager, RepositoryManager $repositoryManager, Locker $locker, InstallationManager $installationManager, EventDispatcher $eventDispatcher, AutoloadGenerator $autoloadGenerator)
|
||||
{
|
||||
$this->io = $io;
|
||||
$this->config = $config;
|
||||
$this->package = $package;
|
||||
$this->downloadManager = $downloadManager;
|
||||
$this->repositoryManager = $repositoryManager;
|
||||
|
@ -201,7 +209,7 @@ class Installer
|
|||
// write autoloader
|
||||
$this->io->write('<info>Generating autoload files</info>');
|
||||
$localRepos = new CompositeRepository($this->repositoryManager->getLocalRepositories());
|
||||
$this->autoloadGenerator->dump($localRepos, $this->package, $this->installationManager, $this->installationManager->getVendorPath() . '/composer');
|
||||
$this->autoloadGenerator->dump($this->config, $localRepos, $this->package, $this->installationManager, 'composer');
|
||||
|
||||
if ($this->runScripts) {
|
||||
// dispatch post event
|
||||
|
@ -561,6 +569,7 @@ class Installer
|
|||
|
||||
return new static(
|
||||
$io,
|
||||
$composer->getConfig(),
|
||||
$composer->getPackage(),
|
||||
$composer->getDownloadManager(),
|
||||
$composer->getRepositoryManager(),
|
||||
|
@ -643,6 +652,19 @@ class Installer
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the config instance
|
||||
*
|
||||
* @param Config $config
|
||||
* @return Installer
|
||||
*/
|
||||
public function setConfig(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* run in verbose mode
|
||||
*
|
||||
|
|
|
@ -35,29 +35,6 @@ class InstallationManager
|
|||
{
|
||||
private $installers = array();
|
||||
private $cache = array();
|
||||
private $vendorPath;
|
||||
|
||||
/**
|
||||
* Creates an instance of InstallationManager
|
||||
*
|
||||
* @param string $vendorDir Relative path to the vendor directory
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($vendorDir = 'vendor')
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
if ($fs->isAbsolutePath($vendorDir)) {
|
||||
$basePath = getcwd();
|
||||
$relativePath = $fs->findShortestPath($basePath.'/file', $vendorDir);
|
||||
if ($fs->isAbsolutePath($relativePath)) {
|
||||
throw new \InvalidArgumentException("Vendor dir ($vendorDir) must be accessible from the directory ($basePath).");
|
||||
}
|
||||
$this->vendorPath = $relativePath;
|
||||
} else {
|
||||
$this->vendorPath = rtrim($vendorDir, '/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds installer
|
||||
|
@ -217,21 +194,6 @@ class InstallationManager
|
|||
return $installer->getInstallPath($package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vendor path
|
||||
*
|
||||
* @param boolean $absolute Whether or not to return an absolute path
|
||||
* @return string path
|
||||
*/
|
||||
public function getVendorPath($absolute = false)
|
||||
{
|
||||
if (!$absolute) {
|
||||
return $this->vendorPath;
|
||||
}
|
||||
|
||||
return getcwd().DIRECTORY_SEPARATOR.$this->vendorPath;
|
||||
}
|
||||
|
||||
private function notifyInstall(PackageInterface $package)
|
||||
{
|
||||
if ($package->getRepository() instanceof NotifiableRepositoryInterface) {
|
||||
|
|
|
@ -21,6 +21,7 @@ use Composer\Test\TestCase;
|
|||
class AutoloadGeneratorTest extends TestCase
|
||||
{
|
||||
public $vendorDir;
|
||||
private $config;
|
||||
private $workingDir;
|
||||
private $im;
|
||||
private $repository;
|
||||
|
@ -36,6 +37,14 @@ class AutoloadGeneratorTest extends TestCase
|
|||
$this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
|
||||
$this->ensureDirectoryExistsAndClear($this->vendorDir);
|
||||
|
||||
$this->config = $this->getMock('Composer\Config');
|
||||
$this->config->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->equalTo('vendor-dir'))
|
||||
->will($this->returnCallback(function () use ($that) {
|
||||
return $that->vendorDir;
|
||||
}));
|
||||
|
||||
$this->dir = getcwd();
|
||||
chdir($this->workingDir);
|
||||
|
||||
|
@ -47,12 +56,6 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->will($this->returnCallback(function ($package) use ($that) {
|
||||
return $that->vendorDir.'/'.$package->getName();
|
||||
}));
|
||||
$this->im->expects($this->any())
|
||||
->method('getVendorPath')
|
||||
->will($this->returnCallback(function () use ($that) {
|
||||
return $that->vendorDir;
|
||||
}));
|
||||
|
||||
$this->repository = $this->getMock('Composer\Repository\RepositoryInterface');
|
||||
|
||||
$this->generator = new AutoloadGenerator();
|
||||
|
@ -92,7 +95,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
|
||||
$this->createClassFile($this->workingDir);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
@ -117,7 +120,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
|
||||
$this->createClassFile($this->vendorDir);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertAutoloadFiles('main3', $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('classmap3', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
@ -137,7 +140,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
$this->vendorDir .= '/subdir';
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
$this->createClassFile($this->workingDir);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertAutoloadFiles('main2', $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('classmap2', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
@ -154,7 +157,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method('getPackages')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
|
||||
}
|
||||
|
||||
|
@ -174,7 +177,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
|
||||
}
|
||||
|
@ -201,7 +204,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
|
||||
file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||
$this->assertEquals(
|
||||
array(
|
||||
|
@ -238,7 +241,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
|
||||
file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||
$this->assertEquals(
|
||||
array(
|
||||
|
@ -270,7 +273,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
|
||||
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
|
||||
|
||||
include $this->vendorDir . '/autoload.php';
|
||||
|
@ -294,7 +297,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer');
|
||||
$this->assertAutoloadFiles('override_vendors', $this->vendorDir.'/composer');
|
||||
}
|
||||
|
||||
|
@ -322,7 +325,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
|
||||
mkdir($this->vendorDir."/composer", 0777, true);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/composer");
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer");
|
||||
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
|
||||
$this->assertEquals(
|
||||
|
@ -351,7 +354,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
|
||||
mkdir($this->vendorDir."/composer", 0777, true);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/composer");
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer");
|
||||
|
||||
$oldIncludePath = get_include_path();
|
||||
|
||||
|
@ -379,7 +382,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
|
||||
mkdir($this->vendorDir."/composer", 0777, true);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/composer");
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer");
|
||||
|
||||
$this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
|
||||
}
|
||||
|
|
|
@ -24,21 +24,6 @@ class InstallationManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$installer = $this->createInstallerMock();
|
||||
|
@ -63,7 +48,6 @@ class InstallationManagerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$manager = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
||||
->setMethods(array('install', 'update', 'uninstall'))
|
||||
->setConstructorArgs(array('vendor'))
|
||||
->getMock();
|
||||
|
||||
$installOperation = new InstallOperation($this->createPackageMock());
|
||||
|
@ -226,18 +210,6 @@ class InstallationManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$manager->uninstall($this->repository, $operation);
|
||||
}
|
||||
|
||||
public function testGetVendorPathAbsolute()
|
||||
{
|
||||
$manager = new InstallationManager('vendor');
|
||||
$this->assertEquals(getcwd().DIRECTORY_SEPARATOR.'vendor', $manager->getVendorPath(true));
|
||||
}
|
||||
|
||||
public function testGetVendorPathRelative()
|
||||
{
|
||||
$manager = new InstallationManager('vendor');
|
||||
$this->assertEquals('vendor', $manager->getVendorPath());
|
||||
}
|
||||
|
||||
private function createInstallerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Composer\Installer\InstallerInterface')
|
||||
|
|
|
@ -55,7 +55,7 @@ class InstallerTest extends TestCase
|
|||
$eventDispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')->disableOriginalConstructor()->getMock();
|
||||
$autoloadGenerator = $this->getMock('Composer\Autoload\AutoloadGenerator');
|
||||
|
||||
$installer = new Installer($io, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
|
||||
$installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
|
||||
$result = $installer->run();
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
|
Loading…
Reference in New Issue