Skip to content

Commit a26b687

Browse files
author
liutao
committed
feat: add event callback
1 parent ee3e6a7 commit a26b687

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/Application.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Psr\Container\ContainerExceptionInterface;
1717
use Psr\Container\NotFoundExceptionInterface;
1818
use ReflectionException;
19+
use Symfony\Component\Console\Output\OutputInterface;
1920
use Throwable;
2021

2122
final class Application
@@ -41,11 +42,11 @@ public static function boot(): Application
4142
/**
4243
* @throws ReflectionException
4344
*/
44-
public function run(): Application
45+
public function run(OutputInterface $output): Application
4546
{
4647
$app = new Application();
4748
$config = $app->init();
48-
$app->listen($config);
49+
$app->listen($config, $output);
4950

5051
return $app;
5152
}
@@ -83,11 +84,11 @@ private function init(): array
8384
return $config;
8485
}
8586

86-
private function listen(array $config): void
87+
private function listen(array $config, OutputInterface $output): void
8788
{
8889
$router = $this->getRouter($config['routes']);
8990
Application::getContainer()->add(Router::class, $router);
90-
ServerFactory::newServer()->run($router);
91+
ServerFactory::newServer()->run($router, $output);
9192
}
9293

9394
private function initDatabase(array $config): void

src/Commands/StartCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3030
$serverConfig = new ServerConfig();
3131

3232
return match ($serverConfig->getDriver()) {
33-
Driver::WORKERMAN => $this->workermanStart(),
33+
Driver::WORKERMAN => $this->workermanStart($output),
3434
Driver::ROADRUNNER => $this->roadrunnerStart($output, $serverConfig),
35-
Driver::SWOOLE => $this->swooleStart(),
36-
Driver::AMP => $this->ampStart(),
35+
Driver::SWOOLE => $this->swooleStart($output),
36+
Driver::AMP => $this->ampStart($output),
3737
default => throw new RuntimeException('unsupported driver: ' . $serverConfig->getDriver()),
3838
};
3939
}
@@ -74,9 +74,9 @@ private function roadrunnerStart(OutputInterface $output, ServerConfig $serverCo
7474
* @throws ReflectionException
7575
* @throws NotFoundExceptionInterface
7676
*/
77-
private function workermanStart(): int
77+
private function workermanStart(OutputInterface $output): int
7878
{
79-
Application::getClass(Application::class)->run();
79+
Application::getClass(Application::class)->run($output);
8080

8181
return Command::SUCCESS;
8282
}
@@ -86,9 +86,9 @@ private function workermanStart(): int
8686
* @throws ReflectionException
8787
* @throws NotFoundExceptionInterface
8888
*/
89-
private function swooleStart(): int
89+
private function swooleStart(OutputInterface $output): int
9090
{
91-
Application::getClass(Application::class)->run();
91+
Application::getClass(Application::class)->run($output);
9292

9393
return Command::SUCCESS;
9494
}
@@ -98,9 +98,9 @@ private function swooleStart(): int
9898
* @throws ReflectionException
9999
* @throws NotFoundExceptionInterface
100100
*/
101-
private function ampStart(): int
101+
private function ampStart(OutputInterface $output): int
102102
{
103-
Application::getClass(Application::class)->run();
103+
Application::getClass(Application::class)->run($output);
104104

105105
return Command::SUCCESS;
106106
}

src/Http/Contract/HttpServerInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
namespace MicroPHP\Framework\Http\Contract;
66

77
use MicroPHP\Framework\Router\Router;
8+
use Symfony\Component\Console\Output\OutputInterface;
89

910
interface HttpServerInterface
1011
{
11-
public function run(Router $router): void;
12+
public function run(Router $router, OutputInterface $output): void;
1213
}

0 commit comments

Comments
 (0)