1
0
Fork 0

Merge remote-tracking branch 'PSeiffert/master'

Conflicts:
	src/Composer/Factory.php
	src/Composer/Repository/RepositoryManager.php
pull/824/merge
Jordi Boggiano 2012-06-23 11:42:13 +02:00
commit de449aa144
6 changed files with 173 additions and 14 deletions

View File

@ -12,6 +12,10 @@
namespace Composer\Command; namespace Composer\Command;
use Composer\Composer;
use Composer\Console\Application;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Symfony\Component\Console\Command\Command as BaseCommand; use Symfony\Component\Console\Command\Command as BaseCommand;
/** /**
@ -23,18 +27,63 @@ use Symfony\Component\Console\Command\Command as BaseCommand;
abstract class Command extends BaseCommand abstract class Command extends BaseCommand
{ {
/** /**
* @return \Composer\Composer * @var \Composer\Composer
*/ */
protected function getComposer($required = true) private $composer;
/**
* @var \Composer\IO\IOInterface
*/
private $io;
/**
* @param bool $required
* @return \Composer\Composer
*/
public function getComposer($required = true)
{ {
return $this->getApplication()->getComposer($required); if (null === $this->composer) {
$application = $this->getApplication();
if ($application instanceof Application) {
/* @var $application Application */
$this->composer = $application->getComposer();
}
}
return $this->composer;
} }
/** /**
* @return \Composer\IO\ConsoleIO * @param \Composer\Composer $composer
*/ */
protected function getIO() public function setComposer(Composer $composer)
{ {
return $this->getApplication()->getIO(); $this->composer = $composer;
}
/**
* @return \Composer\IO\IOInterface
*/
public function getIO()
{
if (null === $this->io) {
$application = $this->getApplication();
if ($application instanceof Application) {
/* @var $application Application */
$this->io = $application->getIO();
} else {
$this->io = new NullIO();
}
}
return $this->io;
}
/**
* @param \Composer\IO\IOInterface $io
*/
public function setIO(IOInterface $io)
{
$this->io = $io;
} }
} }

View File

@ -26,68 +26,128 @@ class Composer
{ {
const VERSION = '@package_version@'; const VERSION = '@package_version@';
/**
* @var Package\PackageInterface
*/
private $package; private $package;
/**
* @var Locker
*/
private $locker; private $locker;
/**
* @var Repository\RepositoryManager
*/
private $repositoryManager; private $repositoryManager;
/**
* @var Downloader\DownloadManager
*/
private $downloadManager; private $downloadManager;
/**
* @var Installer\InstallationManager
*/
private $installationManager; private $installationManager;
/**
* @var Config
*/
private $config;
/**
* @param Package\PackageInterface $package
* @return void
*/
public function setPackage(PackageInterface $package) public function setPackage(PackageInterface $package)
{ {
$this->package = $package; $this->package = $package;
} }
/**
* @return Package\PackageInterface
*/
public function getPackage() public function getPackage()
{ {
return $this->package; return $this->package;
} }
/**
* @param Config $config
*/
public function setConfig(Config $config) public function setConfig(Config $config)
{ {
$this->config = $config; $this->config = $config;
} }
/**
* @return Config
*/
public function getConfig() public function getConfig()
{ {
return $this->config; return $this->config;
} }
/**
* @param Package\Locker $locker
*/
public function setLocker(Locker $locker) public function setLocker(Locker $locker)
{ {
$this->locker = $locker; $this->locker = $locker;
} }
/**
* @return Package\Locker
*/
public function getLocker() public function getLocker()
{ {
return $this->locker; return $this->locker;
} }
/**
* @param Repository\RepositoryManager $manager
*/
public function setRepositoryManager(RepositoryManager $manager) public function setRepositoryManager(RepositoryManager $manager)
{ {
$this->repositoryManager = $manager; $this->repositoryManager = $manager;
} }
/**
* @return Repository\RepositoryManager
*/
public function getRepositoryManager() public function getRepositoryManager()
{ {
return $this->repositoryManager; return $this->repositoryManager;
} }
/**
* @param Downloader\DownloadManager $manager
*/
public function setDownloadManager(DownloadManager $manager) public function setDownloadManager(DownloadManager $manager)
{ {
$this->downloadManager = $manager; $this->downloadManager = $manager;
} }
/**
* @return Doenloader\DownloadManager
*/
public function getDownloadManager() public function getDownloadManager()
{ {
return $this->downloadManager; return $this->downloadManager;
} }
/**
* @param Installer\InstallationManager $manager
*/
public function setInstallationManager(InstallationManager $manager) public function setInstallationManager(InstallationManager $manager)
{ {
$this->installationManager = $manager; $this->installationManager = $manager;
} }
/**
* @return Installer\InstallationManager
*/
public function getInstallationManager() public function getInstallationManager()
{ {
return $this->installationManager; return $this->installationManager;

View File

@ -35,7 +35,14 @@ use Composer\Util\ErrorHandler;
*/ */
class Application extends BaseApplication class Application extends BaseApplication
{ {
/**
* @var Composer
*/
protected $composer; protected $composer;
/**
* @var ConsoleIO
*/
protected $io; protected $io;
public function __construct() public function __construct()
@ -74,7 +81,8 @@ class Application extends BaseApplication
} }
/** /**
* @return Composer * @param bool $required
* @return \Composer\Composer
*/ */
public function getComposer($required = true) public function getComposer($required = true)
{ {
@ -86,8 +94,6 @@ class Application extends BaseApplication
$this->io->write($e->getMessage()); $this->io->write($e->getMessage());
exit(1); exit(1);
} }
return;
} }
} }

View File

@ -70,9 +70,11 @@ class Factory
/** /**
* Creates a Composer instance * Creates a Composer instance
* *
* @param IOInterface $io IO instance * @param IOInterface $io IO instance
* @param mixed $localConfig either a configuration array or a filename to read from, if null it will read from the default filename * @param array|string|null $localConfig either a configuration array or a filename to read from, if null it will
* @return Composer * read from the default filename
* @throws \InvalidArgumentException
* @return Composer
*/ */
public function createComposer(IOInterface $io, $localConfig = null) public function createComposer(IOInterface $io, $localConfig = null)
{ {
@ -151,6 +153,11 @@ class Factory
return $composer; return $composer;
} }
/**
* @param IO\IOInterface $io
* @param Config $config
* @return Repository\RepositoryManager
*/
protected function createRepositoryManager(IOInterface $io, Config $config) protected function createRepositoryManager(IOInterface $io, Config $config)
{ {
$rm = new RepositoryManager($io, $config); $rm = new RepositoryManager($io, $config);
@ -165,12 +172,20 @@ class Factory
return $rm; return $rm;
} }
/**
* @param Repository\RepositoryManager $rm
* @param string $vendorDir
*/
protected function addLocalRepository(RepositoryManager $rm, $vendorDir) protected function addLocalRepository(RepositoryManager $rm, $vendorDir)
{ {
$rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed.json'))); $rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed.json')));
$rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed_dev.json'))); $rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed_dev.json')));
} }
/**
* @param array $localConfig
* @return array
*/
protected function addPackagistRepository(array $localConfig) protected function addPackagistRepository(array $localConfig)
{ {
$loadPackagist = true; $loadPackagist = true;
@ -201,6 +216,10 @@ class Factory
return $localConfig; return $localConfig;
} }
/**
* @param IO\IOInterface $io
* @return Downloader\DownloadManager
*/
public function createDownloadManager(IOInterface $io) public function createDownloadManager(IOInterface $io)
{ {
$dm = new Downloader\DownloadManager(); $dm = new Downloader\DownloadManager();
@ -216,6 +235,14 @@ class Factory
return $dm; return $dm;
} }
/**
* @param Repository\RepositoryManager $rm
* @param Downloader\DownloadManager $dm
* @param string $vendorDir
* @param string $binDir
* @param IO\IOInterface $io
* @return Installer\InstallationManager
*/
protected function createInstallationManager(Repository\RepositoryManager $rm, Downloader\DownloadManager $dm, $vendorDir, $binDir, IOInterface $io) protected function createInstallationManager(Repository\RepositoryManager $rm, Downloader\DownloadManager $dm, $vendorDir, $binDir, IOInterface $io)
{ {
$im = new Installer\InstallationManager($vendorDir); $im = new Installer\InstallationManager($vendorDir);
@ -226,9 +253,14 @@ class Factory
return $im; return $im;
} }
/**
* @param Repository\RepositoryManager $rm
* @param Installer\InstallationManager $im
*/
protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im) protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im)
{ {
foreach ($rm->getLocalRepositories() as $repo) { foreach ($rm->getLocalRepositories() as $repo) {
/* @var $repo Repository\WritableRepositoryInterface */
foreach ($repo->getPackages() as $package) { foreach ($repo->getPackages() as $package) {
if (!$im->isPackageInstalled($repo, $package)) { if (!$im->isPackageInstalled($repo, $package)) {
$repo->removePackage($package); $repo->removePackage($package);
@ -239,7 +271,8 @@ class Factory
/** /**
* @param IOInterface $io IO instance * @param IOInterface $io IO instance
* @param mixed $config either a configuration array or a filename to read from, if null it will read from the default filename * @param mixed $config either a configuration array or a filename to read from, if null it will read from
* the default filename
* @return Composer * @return Composer
*/ */
public static function create(IOInterface $io, $config = null) public static function create(IOInterface $io, $config = null)

View File

@ -105,6 +105,17 @@ class CompositeRepository implements RepositoryInterface
return call_user_func_array('array_merge', $packages); return call_user_func_array('array_merge', $packages);
} }
/**
* {@inheritdoc}
*/
public function removePackage(PackageInterface $package)
{
foreach($this->repositories as $repository) {
/* @var $repository RepositoryInterface */
$repository->removePackage($package);
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -166,7 +166,7 @@ class RepositoryManager
/** /**
* Returns all local repositories for the project. * Returns all local repositories for the project.
* *
* @return array[RepositoryInterface] * @return array[WritableRepositoryInterface]
*/ */
public function getLocalRepositories() public function getLocalRepositories()
{ {