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;
use Composer\Composer;
use Composer\Console\Application;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
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
{
/**
* @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@';
/**
* @var Package\PackageInterface
*/
private $package;
/**
* @var Locker
*/
private $locker;
/**
* @var Repository\RepositoryManager
*/
private $repositoryManager;
/**
* @var Downloader\DownloadManager
*/
private $downloadManager;
/**
* @var Installer\InstallationManager
*/
private $installationManager;
/**
* @var Config
*/
private $config;
/**
* @param Package\PackageInterface $package
* @return void
*/
public function setPackage(PackageInterface $package)
{
$this->package = $package;
}
/**
* @return Package\PackageInterface
*/
public function getPackage()
{
return $this->package;
}
/**
* @param Config $config
*/
public function setConfig(Config $config)
{
$this->config = $config;
}
/**
* @return Config
*/
public function getConfig()
{
return $this->config;
}
/**
* @param Package\Locker $locker
*/
public function setLocker(Locker $locker)
{
$this->locker = $locker;
}
/**
* @return Package\Locker
*/
public function getLocker()
{
return $this->locker;
}
/**
* @param Repository\RepositoryManager $manager
*/
public function setRepositoryManager(RepositoryManager $manager)
{
$this->repositoryManager = $manager;
}
/**
* @return Repository\RepositoryManager
*/
public function getRepositoryManager()
{
return $this->repositoryManager;
}
/**
* @param Downloader\DownloadManager $manager
*/
public function setDownloadManager(DownloadManager $manager)
{
$this->downloadManager = $manager;
}
/**
* @return Doenloader\DownloadManager
*/
public function getDownloadManager()
{
return $this->downloadManager;
}
/**
* @param Installer\InstallationManager $manager
*/
public function setInstallationManager(InstallationManager $manager)
{
$this->installationManager = $manager;
}
/**
* @return Installer\InstallationManager
*/
public function getInstallationManager()
{
return $this->installationManager;

View File

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

View File

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

View File

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