From 013d145bcdf51e1aa5c6994e22fec5a0caf7f107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pluchino?= Date: Tue, 10 Jan 2012 18:50:16 +0100 Subject: [PATCH] Add InputInterface and OutputInterface --- src/Composer/Console/Application.php | 18 ++++++++++++------ src/Composer/Downloader/FileDownloader.php | 17 +++++++++++++++++ src/Composer/Repository/ComposerRepository.php | 10 +++++++++- src/Composer/Repository/PackageRepository.php | 13 +++++++++++-- src/Composer/Repository/PearRepository.php | 9 ++++++++- src/Composer/Repository/RepositoryManager.php | 14 +++++++++++++- .../Repository/Vcs/GitBitbucketDriver.php | 7 +++++-- src/Composer/Repository/Vcs/GitDriver.php | 11 +++++++---- src/Composer/Repository/Vcs/GitHubDriver.php | 7 +++++-- .../Repository/Vcs/HgBitbucketDriver.php | 7 +++++-- src/Composer/Repository/Vcs/HgDriver.php | 7 +++++-- src/Composer/Repository/Vcs/SvnDriver.php | 7 +++++-- src/Composer/Repository/Vcs/VcsDriver.php | 14 ++++++++++++-- src/Composer/Repository/VcsRepository.php | 13 ++++++++++--- 14 files changed, 124 insertions(+), 30 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index af68185be..0d24dfe7c 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -32,10 +32,13 @@ use Composer\Json\JsonFile; * * @author Ryan Weaver * @author Jordi Boggiano + * @author François Pluchino */ 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 diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index aeb655be4..08769ff60 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -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} */ diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index fadfd6a7c..8a78af773 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -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 + * @author François Pluchino */ 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']; diff --git a/src/Composer/Repository/PackageRepository.php b/src/Composer/Repository/PackageRepository.php index 01b1b24c2..113e8c0b7 100644 --- a/src/Composer/Repository/PackageRepository.php +++ b/src/Composer/Repository/PackageRepository.php @@ -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 + * @author François Pluchino */ 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; } /** diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index b19620b3a..ae26e5579 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -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 * @author Jordi Boggiano + * @author François Pluchino */ 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() diff --git a/src/Composer/Repository/RepositoryManager.php b/src/Composer/Repository/RepositoryManager.php index a73934d3f..1157ae493 100644 --- a/src/Composer/Repository/RepositoryManager.php +++ b/src/Composer/Repository/RepositoryManager.php @@ -12,17 +12,29 @@ namespace Composer\Repository; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputInterface; + /** * Repositories manager. * * @author Jordi Boggiano * @author Konstantin Kudryashov + * @author François Pluchino */ 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); } /** diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index 1255704c2..75bf2d7b2 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -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 + * @author François Pluchino */ 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); } /** diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 1da392667..09afc0c8e 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -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 + * @author François Pluchino */ -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); } /** diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 2168154cf..e7c0efbb7 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -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 + * @author François Pluchino */ 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); } /** diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 721f7fd52..0c3b59ced 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -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 + * @author François Pluchino */ 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); } /** diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index b3057c398..366cd7b88 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -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 + * @author François Pluchino */ 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); } /** diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index 830382385..f6a27feac 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -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 + * @author François Pluchino */ 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); diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index 0b2dc824b..703f7b16c 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -17,18 +17,28 @@ namespace Composer\Repository\Vcs; * * @author François Pluchino */ + +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; } /** diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 9b66963bc..52802c5a5 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -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 + * @author François Pluchino */ 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; }