From b65df7080999a8b578c8cc7709164571bc6de81d Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sun, 13 Jan 2019 21:33:45 +0800 Subject: [PATCH] add support for Lumen 5.7 --- src/Concerns/WithApplication.php | 32 ++++++-------------------------- tests/Server/ManagerTest.php | 6 +----- tests/fixtures/bootstrap/app.php | 22 +++------------------- 3 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/Concerns/WithApplication.php b/src/Concerns/WithApplication.php index 6ead455f..63f0cdcd 100644 --- a/src/Concerns/WithApplication.php +++ b/src/Concerns/WithApplication.php @@ -24,15 +24,17 @@ trait WithApplication /** * Bootstrap framework. - * - * @throws \ReflectionException */ protected function bootstrap() { if ($this->framework === 'laravel') { - $bootstrappers = $this->getBootstrappers(); - $this->app->bootstrapWith($bootstrappers); + $this->app->bootstrap(); } else { + // for Lumen 5.7 + // https://github.com/laravel/lumen-framework/commit/42cbc998375718b1a8a11883e033617024e57260#diff-c9248b3167fc44af085b81db2e292837 + if (method_exists($this->app, 'boot')) { + $this->app->boot(); + } if (is_null(Facade::getFacadeApplication())) { $this->app->withFacades(); } @@ -75,28 +77,6 @@ public function setApplication(Container $app) $this->app = $app; } - /** - * Get bootstrappers. - * - * @return array - * @throws \ReflectionException - */ - protected function getBootstrappers() - { - $kernel = $this->getApplication()->make(Kernel::class); - - $reflection = new \ReflectionObject($kernel); - - $bootstrappersMethod = $reflection->getMethod('bootstrappers'); - $bootstrappersMethod->setAccessible(true); - - $bootstrappers = $bootstrappersMethod->invoke($kernel); - - array_splice($bootstrappers, -2, 0, ['Illuminate\Foundation\Bootstrap\SetRequestForConsole']); - - return $bootstrappers; - } - /** * Set framework. * diff --git a/tests/Server/ManagerTest.php b/tests/Server/ManagerTest.php index fab6ab3f..a667003b 100644 --- a/tests/Server/ManagerTest.php +++ b/tests/Server/ManagerTest.php @@ -155,9 +155,7 @@ public function testOnWorkerStart() public function testLoadApplication() { $server = $this->getServer(); - $this->getManager(); - - $container = $this->getContainer($this->getServer(), $this->getConfig()); + $container = $this->getContainer($server, $this->getConfig()); $container->singleton('events', function () { return $this->getEvent('swoole.workerStart'); }); @@ -165,8 +163,6 @@ public function testLoadApplication() $path = __DIR__ . '/../fixtures'; $manager = $this->getManager($container, $framework = 'laravel', $path); $manager->onWorkerStart($server); - - $manager->getApplication(); } public function testOnTaskWorkerStart() diff --git a/tests/fixtures/bootstrap/app.php b/tests/fixtures/bootstrap/app.php index ed346bb1..aafbe347 100644 --- a/tests/fixtures/bootstrap/app.php +++ b/tests/fixtures/bootstrap/app.php @@ -1,19 +1,11 @@ shouldReceive('make') - ->with(Kernel::class) - ->once() - ->andReturn($kernel); -$app->shouldReceive('bootstrapWith') - ->once() - ->andReturn($kernel); +$app->shouldReceive('bootstrap') + ->once(); $app->shouldReceive('offsetExists') ->with('foo') ->once() @@ -25,11 +17,3 @@ $app->shouldReceive('alias'); return $app; - -class TestKernel -{ - public function bootstrappers() - { - return []; - } -} \ No newline at end of file