1919
2020namespace FastForward \DevTools \Console \Input ;
2121
22- use Ergebnis \ AgentDetector \ Detector ;
22+ use FastForward \ DevTools \ Container \ ContainerFactory ;
2323use FastForward \DevTools \Environment \RuntimeEnvironmentInterface ;
2424use Symfony \Component \Console \Input \InputInterface ;
2525use Symfony \Component \Console \Input \InputOption ;
@@ -80,22 +80,21 @@ protected function isPrettyJsonOutput(InputInterface $input): bool
8080 *
8181 * Commands MAY opt into runtime-environment-aware behavior by exposing a
8282 * `$runtimeEnvironment` property. Commands that do not expose it SHALL fall
83- * back to lightweight agent detection based on process environment
84- * variables, except while the PHPUnit test runtime is active.
83+ * back to the shared runtime-environment service from the DevTools container.
8584 */
8685 private function isImplicitJsonOutputEnabled (): bool
8786 {
8887 $ runtimeEnvironment = $ this ->resolveRuntimeEnvironment ();
8988
90- if ($ runtimeEnvironment instanceof RuntimeEnvironmentInterface) {
91- return $ runtimeEnvironment-> isAgentPresent () && ! $ runtimeEnvironment -> isComposerTestRun ( );
89+ if (! $ runtimeEnvironment instanceof RuntimeEnvironmentInterface) {
90+ $ runtimeEnvironment = ContainerFactory:: get (RuntimeEnvironmentInterface::class );
9291 }
9392
94- if ($ this -> isPhpUnitRuntime () || $ this -> isComposerTestRunEnvironmentEnabled () ) {
93+ if (! $ runtimeEnvironment instanceof RuntimeEnvironmentInterface ) {
9594 return false ;
9695 }
9796
98- return ( new Detector ()) ->isAgentPresent ($ this -> resolveEnvironmentVariables () );
97+ return $ runtimeEnvironment ->isAgentPresent () && ! $ runtimeEnvironment -> isComposerTestRun ( );
9998 }
10099
101100 /**
@@ -113,48 +112,4 @@ private function resolveRuntimeEnvironment(): ?RuntimeEnvironmentInterface
113112
114113 return $ this ->runtimeEnvironment ;
115114 }
116-
117- /**
118- * Returns whether the current process is executing inside PHPUnit.
119- */
120- private function isPhpUnitRuntime (): bool
121- {
122- return \defined ('PHPUNIT_COMPOSER_INSTALL ' );
123- }
124-
125- /**
126- * Returns whether the Composer test runtime flag is enabled.
127- */
128- private function isComposerTestRunEnvironmentEnabled (): bool
129- {
130- $ value = $ _SERVER ['COMPOSER_TESTS_ARE_RUNNING ' ] ?? getenv ('COMPOSER_TESTS_ARE_RUNNING ' );
131-
132- if (false === $ value || null === $ value ) {
133- return false ;
134- }
135-
136- return \in_array (strtolower ((string ) $ value ), ['1 ' , 'true ' , 'yes ' , 'on ' ], true );
137- }
138-
139- /**
140- * Returns environment variables suitable for lightweight agent detection.
141- *
142- * @return array<string, string>
143- */
144- private function resolveEnvironmentVariables (): array
145- {
146- $ environmentVariables = [];
147-
148- foreach ([$ _SERVER , $ _ENV ] as $ environment ) {
149- foreach ($ environment as $ name => $ value ) {
150- if (! \is_string ($ name ) || ! \is_string ($ value )) {
151- continue ;
152- }
153-
154- $ environmentVariables [$ name ] ??= $ value ;
155- }
156- }
157-
158- return $ environmentVariables ;
159- }
160115}
0 commit comments