Add InputInterface and OutputInterface

main
François Pluchino 13 years ago
parent fa793649fa
commit 013d145bcd

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

@ -12,6 +12,8 @@
namespace Composer\Downloader; namespace Composer\Downloader;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/** /**
* Base downloader for file packages * Base downloader for file packages
@ -21,6 +23,21 @@ use Composer\Package\PackageInterface;
*/ */
abstract class FileDownloader implements DownloaderInterface 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} * {@inheritDoc}
*/ */

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

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

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

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

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

@ -3,22 +3,25 @@
namespace Composer\Repository\Vcs; namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @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 $tags;
protected $branches; protected $branches;
protected $rootIdentifier; protected $rootIdentifier;
protected $infoCache = array(); 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) . '/'; $this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/';
parent::__construct($url, $input, $output);
} }
/** /**

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

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

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

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

@ -17,18 +17,28 @@ namespace Composer\Repository\Vcs;
* *
* @author François Pluchino <francois.pluchino@opendisplay.com> * @author François Pluchino <francois.pluchino@opendisplay.com>
*/ */
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
abstract class VcsDriver abstract class VcsDriver
{ {
protected $url; protected $url;
protected $input;
protected $output;
/** /**
* Constructor * 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->url = $url;
$this->input = $input;
$this->output = $output;
} }
/** /**

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

Loading…
Cancel
Save