22
33declare (strict_types=1 );
44
5- namespace Boson \Api \DetachConsole ;
5+ namespace Boson \Api \Console ;
66
7- use Boson \Api \DetachConsole \Driver \DetachConsoleDriverInterface ;
8- use Boson \Api \DetachConsole \Driver \WindowsDetachConsoleDriver ;
7+ use Boson \Api \Console \Driver \ConsoleDriverInterface ;
8+ use Boson \Api \Console \Driver \WindowsConsoleDriver ;
9+ use Boson \Api \Console \Event \ConsoleDetached ;
10+ use Boson \Api \Console \Event \ConsoleDetaching ;
911use Boson \Api \OperatingSystem \OperatingSystemExtensionInterface ;
1012use Boson \Api \OperatingSystem \OperatingSystemExtensionProvider ;
1113use Boson \Application ;
2022 * @template-extends ExtensionProvider<Application>
2123 */
2224#[DependsOn(OperatingSystemExtensionProvider::class)]
23- final class DetachConsoleExtensionProvider extends ExtensionProvider
25+ final class ConsoleExtensionProvider extends ExtensionProvider
2426{
2527 public function load (IdentifiableInterface $ ctx , EventListener $ listener ): null
2628 {
@@ -29,21 +31,29 @@ public function load(IdentifiableInterface $ctx, EventListener $listener): null
2931 // Detach console in case of:
3032 // 1) Debug mode is disabled
3133 // 2) And application running in PHAR
32- if ($ ctx ->isDebug && $ this ->isRunningInPhar ()) {
33- $ driver ?->detach();
34+ if ($ driver !== null && $ ctx ->isDebug && $ this ->isRunningInPhar ()) {
35+ $ listener ->dispatch ($ intention = new ConsoleDetaching ($ ctx , $ driver ));
36+
37+ if ($ intention ->isCancelled ) {
38+ return null ;
39+ }
40+
41+ $ driver ->detach ();
42+
43+ $ listener ->dispatch (new ConsoleDetached ($ ctx , $ driver ));
3444 }
3545
3646 return null ;
3747 }
3848
39- private function createDriver (OperatingSystemExtensionInterface $ operatingSystem ): ?DetachConsoleDriverInterface
49+ private function createDriver (OperatingSystemExtensionInterface $ operatingSystem ): ?ConsoleDriverInterface
4050 {
4151 if (!Runtime::isAvailable ()) {
4252 return null ;
4353 }
4454
4555 if ($ operatingSystem ->family ->is (Family::Windows)) {
46- return new WindowsDetachConsoleDriver ();
56+ return new WindowsConsoleDriver ();
4757 }
4858
4959 return null ;
0 commit comments