1
0
Fork 0

Add InputInterface and OutputInterface

pull/198/head
François Pluchino 2012-01-10 18:50:16 +01:00
parent fa793649fa
commit 013d145bcd
14 changed files with 124 additions and 30 deletions

View File

@ -32,10 +32,13 @@ use Composer\Json\JsonFile;
*
* @author Ryan Weaver <ryan@knplabs.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class Application extends BaseApplication
{
protected $composer;
protected $input;
protected $output;
public function __construct()
{
@ -64,6 +67,9 @@ class Application extends BaseApplication
{
$this->registerCommands();
$this->input = $input;
$this->output = $output;
return parent::doRun($input, $output);
}
@ -73,7 +79,7 @@ class Application extends BaseApplication
public function getComposer()
{
if (null === $this->composer) {
$this->composer = self::bootstrapComposer();
$this->composer = self::bootstrapComposer(null, $this->input, $this->output);
}
return $this->composer;
@ -84,7 +90,7 @@ class Application extends BaseApplication
*
* @return Composer
*/
public static function bootstrapComposer($composerFile = null)
public static function bootstrapComposer($composerFile = null, InputInterface $input = null, OutputInterface $output = null)
{
// load Composer configuration
if (null === $composerFile) {
@ -122,7 +128,7 @@ class Application extends BaseApplication
$binDir = getenv('COMPOSER_BIN_DIR') ?: $packageConfig['config']['bin-dir'];
// initialize repository manager
$rm = new Repository\RepositoryManager();
$rm = new Repository\RepositoryManager($input, $output);
$rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json')));
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
@ -134,8 +140,8 @@ class Application extends BaseApplication
$dm->setDownloader('git', new Downloader\GitDownloader());
$dm->setDownloader('svn', new Downloader\SvnDownloader());
$dm->setDownloader('hg', new Downloader\HgDownloader());
$dm->setDownloader('pear', new Downloader\PearDownloader());
$dm->setDownloader('zip', new Downloader\ZipDownloader());
$dm->setDownloader('pear', new Downloader\PearDownloader($input, $output));
$dm->setDownloader('zip', new Downloader\ZipDownloader($input, $output));
// initialize installation manager
$im = new Installer\InstallationManager($vendorDir);
@ -148,7 +154,7 @@ class Application extends BaseApplication
// load default repository unless it's explicitly disabled
if (!isset($packageConfig['repositories']['packagist']) || $packageConfig['repositories']['packagist'] !== false) {
$rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org')));
$rm->addRepository(new Repository\ComposerRepository($input, $output, array('url' => 'http://packagist.org')));
}
// init locker

View File

@ -12,6 +12,8 @@
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* Base downloader for file packages
@ -21,6 +23,21 @@ use Composer\Package\PackageInterface;
*/
abstract class FileDownloader implements DownloaderInterface
{
protected $intput;
protected $output;
/**
* Constructor.
*
* @param InputInterface $input The Input instance
* @param OutputInterface $output The Output instance
*/
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->intput = $input;
$this->output = $output;
}
/**
* {@inheritDoc}
*/

View File

@ -15,17 +15,25 @@ namespace Composer\Repository;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class ComposerRepository extends ArrayRepository
{
protected $url;
protected $packages;
protected $input;
protected $output;
public function __construct(array $config)
public function __construct(InputInterface $input, OutputInterface $output, array $config)
{
$this->input = $input;
$this->output = $output;
if (!preg_match('{^\w+://}', $config['url'])) {
// assume http as the default protocol
$config['url'] = 'http://'.$config['url'];

View File

@ -16,24 +16,33 @@ use Composer\Json\JsonFile;
use Composer\Package\PackageInterface;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* Package repository.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class PackageRepository extends ArrayRepository
{
private $config;
private $input;
private $output;
/**
* Initializes filesystem repository.
*
* @param array $config package definition
* @param InputInterface $input The Input instance
* @param OutputInterface $output The Output instance
* @param array $config package definition
*/
public function __construct(array $config)
public function __construct(InputInterface $input, OutputInterface $output, array $config)
{
$this->config = $config;
$this->input = $input;
$this->output = $output;
}
/**

View File

@ -13,16 +13,21 @@
namespace Composer\Repository;
use Composer\Package\Loader\ArrayLoader;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class PearRepository extends ArrayRepository
{
protected $url;
private $input;
private $output;
public function __construct(array $config)
public function __construct(InputInterface $input, OutputInterface $output, array $config)
{
if (!preg_match('{^https?://}', $config['url'])) {
$config['url'] = 'http://'.$config['url'];
@ -32,6 +37,8 @@ class PearRepository extends ArrayRepository
}
$this->url = $config['url'];
$this->input = $input;
$this->output = $output;
}
protected function initialize()

View File

@ -12,17 +12,29 @@
namespace Composer\Repository;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* Repositories manager.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Konstantin Kudryashov <ever.zet@gmail.com>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class RepositoryManager
{
private $localRepository;
private $repositories = array();
private $repositoryClasses = array();
private $input;
private $output;
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
}
/**
* Searches for a package by it's name and version in managed repositories.
@ -66,7 +78,7 @@ class RepositoryManager
}
$class = $this->repositoryClasses[$type];
return new $class($config);
return new $class($this->input, $this->output, $config);
}
/**

View File

@ -13,9 +13,12 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Per Bernhardt <plb@webfactory.de>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
{
@ -27,13 +30,13 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
protected $rootIdentifier;
protected $infoCache = array();
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
preg_match('#^(?:https?|http)://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url, $match);
$this->owner = $match[1];
$this->repository = $match[2];
parent::__construct($url);
parent::__construct($url, $input, $output);
}
/**

View File

@ -3,22 +3,25 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class GitDriver implements VcsDriverInterface
class GitDriver extends VcsDriver implements VcsDriverInterface
{
protected $url;
protected $tags;
protected $branches;
protected $rootIdentifier;
protected $infoCache = array();
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
$this->url = $url;
$this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/';
parent::__construct($url, $input, $output);
}
/**

View File

@ -3,9 +3,12 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class GitHubDriver extends VcsDriver implements VcsDriverInterface
{
@ -16,13 +19,13 @@ class GitHubDriver extends VcsDriver implements VcsDriverInterface
protected $rootIdentifier;
protected $infoCache = array();
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
preg_match('#^(?:https?|http|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url, $match);
$this->owner = $match[1];
$this->repository = $match[2];
parent::__construct($url);
parent::__construct($url, $input, $output);
}
/**

View File

@ -13,9 +13,12 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Per Bernhardt <plb@webfactory.de>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class HgBitbucketDriver extends VcsDriver implements VcsDriverInterface
{
@ -26,13 +29,13 @@ class HgBitbucketDriver extends VcsDriver implements VcsDriverInterface
protected $rootIdentifier;
protected $infoCache = array();
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
preg_match('#^(?:https?|http)://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url, $match);
$this->owner = $match[1];
$this->repository = $match[2];
parent::__construct($url);
parent::__construct($url, $input, $output);
}
/**

View File

@ -13,9 +13,12 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Per Bernhardt <plb@webfactory.de>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class HgDriver extends VcsDriver implements VcsDriverInterface
{
@ -24,11 +27,11 @@ class HgDriver extends VcsDriver implements VcsDriverInterface
protected $rootIdentifier;
protected $infoCache = array();
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
$this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/';
parent::__construct($url);
parent::__construct($url, $input, $output);
}
/**

View File

@ -3,9 +3,12 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class SvnDriver extends VcsDriver implements VcsDriverInterface
{
@ -14,9 +17,9 @@ class SvnDriver extends VcsDriver implements VcsDriverInterface
protected $branches;
protected $infoCache = array();
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
parent::__construct($this->baseUrl = rtrim($url, '/'));
parent::__construct($this->baseUrl = rtrim($url, '/'), $input, $output);
if (false !== ($pos = strrpos($url, '/trunk'))) {
$this->baseUrl = substr($url, 0, $pos);

View File

@ -17,18 +17,28 @@ namespace Composer\Repository\Vcs;
*
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
abstract class VcsDriver
{
protected $url;
protected $input;
protected $output;
/**
* Constructor
*
* @param string $url The URL
* @param string $url The URL
* @param InputInterface $input The Input instance
* @param OutputInterface $output The output instance
*/
public function __construct($url)
public function __construct($url, InputInterface $input, OutputInterface $output)
{
$this->url = $url;
$this->input = $input;
$this->output = $output;
}
/**

View File

@ -5,17 +5,22 @@ namespace Composer\Repository;
use Composer\Repository\Vcs\VcsDriverInterface;
use Composer\Package\Version\VersionParser;
use Composer\Package\Loader\ArrayLoader;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author François Pluchino <francois.pluchino@opendisplay.com>
*/
class VcsRepository extends ArrayRepository
{
protected $url;
protected $packageName;
protected $debug;
protected $debug;
protected $input;
protected $output;
public function __construct(array $config, array $drivers = null)
public function __construct(InputInterface $input, OutputInterface $output, array $config, array $drivers = null)
{
if (!filter_var($config['url'], FILTER_VALIDATE_URL)) {
throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']);
@ -31,6 +36,8 @@ class VcsRepository extends ArrayRepository
);
$this->url = $config['url'];
$this->input = $input;
$this->output = $output;
}
public function setDebug($debug)
@ -42,7 +49,7 @@ class VcsRepository extends ArrayRepository
{
foreach ($this->drivers as $driver) {
if ($driver::supports($this->url)) {
$driver = new $driver($this->url);
$driver = new $driver($this->url, $this->input, $this->output);
$driver->initialize();
return $driver;
}