44
55namespace Php \Pie ;
66
7- use Composer \Util \Platform ;
7+ use Composer \Util \Platform as ComposerPlatform ;
88use Illuminate \Container \Container as IlluminateContainer ;
99use Php \Pie \Building \Build ;
1010use Php \Pie \Building \UnixBuild ;
4444use Symfony \Component \Console \Output \OutputInterface ;
4545use Symfony \Component \EventDispatcher \EventDispatcher ;
4646
47+ use function defined ;
48+ use function fopen ;
4749use function getcwd ;
4850use function str_starts_with ;
4951
52+ use const STDIN ;
53+
5054/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
5155final class Container
5256{
5357 public static function factory (): ContainerInterface
5458 {
5559 $ container = new IlluminateContainer ();
5660 $ container ->instance (ContainerInterface::class, $ container );
57- $ container ->instance (InputInterface::class, new ArgvInput ());
61+ $ container ->singleton (
62+ InputInterface::class,
63+ static function () {
64+ $ input = new ArgvInput ();
65+
66+ $ stdin = defined ('STDIN ' ) ? STDIN : fopen ('php://stdin ' , 'r ' );
67+ $ noInteractionEnv = ComposerPlatform::getEnv ('COMPOSER_NO_INTERACTION ' );
68+ if (
69+ $ noInteractionEnv === false
70+ || $ noInteractionEnv === '1 '
71+ || $ stdin === false
72+ || ! ComposerPlatform::isTty ($ stdin )
73+ ) {
74+ $ input ->setInteractive (false );
75+ }
76+
77+ return $ input ;
78+ },
79+ );
5880 $ container ->instance (OutputInterface::class, new ConsoleOutput ());
5981 $ container ->singleton (EventDispatcher::class, static function () {
6082 $ displayedBanner = false ;
@@ -124,7 +146,7 @@ static function (ConsoleCommandEvent $event) use (&$displayedBanner): void {
124146 $ container ->singleton (
125147 Build::class,
126148 static function (ContainerInterface $ container ): Build {
127- if (Platform ::isWindows ()) {
149+ if (ComposerPlatform ::isWindows ()) {
128150 return $ container ->get (WindowsBuild::class);
129151 }
130152
@@ -148,7 +170,7 @@ static function (ContainerInterface $container): Ini\SetupIniApproach {
148170 $ container ->singleton (
149171 Install::class,
150172 static function (ContainerInterface $ container ): Install {
151- if (Platform ::isWindows ()) {
173+ if (ComposerPlatform ::isWindows ()) {
152174 return $ container ->get (WindowsInstall::class);
153175 }
154176
0 commit comments