소스 검색

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.
Théo FIDRY 7 년 전
부모
커밋
b7ab081519
1개의 변경된 파일3개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      src/Composer/Console/Application.php

+ 3 - 0
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);
     }