From b7ab08151937b4e51593ee34563c8cce5aae69ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 24 Mar 2018 07:32:04 +0000 Subject: [PATCH] Allow Composer to be used without running the application For [Humbug Box](https://github.com/humbug/box/blob/master/src/Composer/ComposerOrchestrator.php#L30) we are using Composer to dump the autoload. To do so I'm using the `Composer` class from the application: ```php $composer = (new ComposerApplication())->getComposer(); ``` If you do so however this is going to fail because `Application#io` is null instead of being a `IOInterface` instance. Indeed it is initialised only when the application is run. So one solution is to initialised it with a dummy IO and the right IO object will be set when the application is run as usual. --- src/Composer/Console/Application.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 655b059d7..a7cf26921 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -12,6 +12,7 @@ namespace Composer\Console; +use Composer\IO\NullIO; use Composer\Util\Platform; use Composer\Util\Silencer; use Symfony\Component\Console\Application as BaseApplication; @@ -85,6 +86,8 @@ class Application extends BaseApplication }); } + $this->io = new NullIO(); + parent::__construct('Composer', Composer::VERSION); }