20
20
use Symfony \Component \Console \ConsoleEvents ;
21
21
use Symfony \Component \Console \Event \ConsoleCommandEvent ;
22
22
use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
23
+ use Symfony \Component \Console \Input \InputInterface ;
23
24
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
24
25
use Symfony \Component \Console \Output \OutputInterface ;
25
26
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
@@ -64,6 +65,8 @@ public function __construct(
64
65
bool $ bubble = true ,
65
66
array $ verbosityLevelMap = [],
66
67
private array $ consoleFormatterOptions = [],
68
+ private ?InputInterface $ input = null ,
69
+ private bool $ interactiveOnly = false ,
67
70
) {
68
71
parent ::__construct (Level::Debug, $ bubble );
69
72
@@ -74,7 +77,16 @@ public function __construct(
74
77
75
78
public function isHandling (LogRecord $ record ): bool
76
79
{
77
- return $ this ->updateLevel () && parent ::isHandling ($ record );
80
+ return $ this ->isInteractiveOnlyEnabled () || ($ this ->updateLevel () && parent ::isHandling ($ record ));
81
+ }
82
+
83
+ public function getBubble (): bool
84
+ {
85
+ if ($ this ->isInteractiveOnlyEnabled ()) {
86
+ return false ;
87
+ }
88
+
89
+ return parent ::getBubble ();
78
90
}
79
91
80
92
public function handle (LogRecord $ record ): bool
@@ -84,6 +96,11 @@ public function handle(LogRecord $record): bool
84
96
return $ this ->updateLevel () && parent ::handle ($ record );
85
97
}
86
98
99
+ public function setInput (InputInterface $ input ): void
100
+ {
101
+ $ this ->input = $ input ;
102
+ }
103
+
87
104
/**
88
105
* Sets the console output to use for printing logs.
89
106
*/
@@ -108,6 +125,9 @@ public function close(): void
108
125
*/
109
126
public function onCommand (ConsoleCommandEvent $ event ): void
110
127
{
128
+ $ input = $ event ->getInput ();
129
+ $ this ->setInput ($ input );
130
+
111
131
$ output = $ event ->getOutput ();
112
132
if ($ output instanceof ConsoleOutputInterface) {
113
133
$ output = $ output ->getErrorOutput ();
@@ -173,4 +193,9 @@ private function updateLevel(): bool
173
193
174
194
return true ;
175
195
}
196
+
197
+ private function isInteractiveOnlyEnabled (): bool
198
+ {
199
+ return $ this ->interactiveOnly && $ this ->input !== null && $ this ->input ->isInteractive ();
200
+ }
176
201
}
0 commit comments