Skip to content

Commit bf3f612

Browse files
authored
Resolve components when needed (#59)
1 parent a853329 commit bf3f612

11 files changed

+58
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
66

7+
## v5.2.2
8+
9+
### Changed
10+
11+
- Resolve listener components when needed [#58]
12+
13+
[#58]:https://github.com/spiral/roadrunner-laravel/issues/58
14+
715
## v5.2.1
816

917
### Fixed

src/Listeners/FlushArrayCacheListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ public function handle($event): void
2121
if ($event instanceof WithApplication) {
2222
$app = $event->application();
2323

24+
if (! $app->resolved($cache_abstract = 'cache')) {
25+
return;
26+
}
27+
2428
/** @var ConfigRepository $config */
2529
$config = $app->make(ConfigRepository::class);
2630

2731
/** @var CacheManager $cache_manager */
28-
$cache_manager = $app->make('cache');
32+
$cache_manager = $app->make($cache_abstract);
2933

3034
foreach ($config->get('cache.stores') as $name => $options) {
3135
if (($options['driver'] ?? '') === 'array') {

src/Listeners/FlushAuthenticationStateListener.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ public function handle($event): void
2222
$app = $event->application();
2323

2424
if ($app instanceof \Illuminate\Container\Container) {
25-
$app->forgetInstance('auth.driver');
25+
if ($app->resolved($auth_driver_abstract = 'auth.driver')) {
26+
$app->forgetInstance($auth_driver_abstract);
27+
}
28+
}
29+
30+
if (! $app->resolved($auth_abstract = 'auth')) {
31+
return;
2632
}
2733

2834
/** @var \Illuminate\Auth\AuthManager $auth */
29-
$auth = $app->make('auth');
35+
$auth = $app->make($auth_abstract);
3036

3137
/**
3238
* Method `setApplication` for the Auth Manager available since Laravel v8.35.0.

src/Listeners/ForceHttpsListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ public function handle($event): void
2929
$config = $app->make(ConfigRepository::class);
3030

3131
if ((bool) $config->get(ServiceProvider::getConfigRootKey() . '.force_https', false)) {
32-
/** @var UrlGenerator $url_generator */
33-
$url_generator = $app->make(UrlGenerator::class);
34-
35-
$url_generator->forceScheme('https');
32+
if ($app->resolved($url_generator_abstract = UrlGenerator::class)) {
33+
/** @var UrlGenerator $url_generator */
34+
$url_generator = $app->make($url_generator_abstract);
35+
$url_generator->forceScheme('https');
36+
}
3637

3738
// Set 'HTTPS' server parameter (required for correct working request methods like ::isSecure
3839
// and others)

src/Listeners/RebindAuthorizationGateListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ public function handle($event): void
2222
if ($event instanceof WithApplication) {
2323
$app = $event->application();
2424

25+
if (! $app->resolved($gate_abstract = Gate::class)) {
26+
return;
27+
}
28+
2529
/** @var Gate $gate */
26-
$gate = $app->make(Gate::class);
30+
$gate = $app->make($gate_abstract);
2731

2832
/**
2933
* Method `setContainer` for the Gate implementation available since Laravel v8.35.0.

src/Listeners/RebindBroadcastManagerListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ public function handle($event): void
2222
if ($event instanceof WithApplication) {
2323
$app = $event->application();
2424

25+
if (! $app->resolved($broadcast_manager_abstract = BroadcastManager::class)) {
26+
return;
27+
}
28+
2529
/** @var BroadcastManager $broadcast_manager */
26-
$broadcast_manager = $app->make(BroadcastManager::class);
30+
$broadcast_manager = $app->make($broadcast_manager_abstract);
2731

2832
/**
2933
* Method `setApplication` for the BroadcastManager available since Laravel v8.35.0.

src/Listeners/RebindDatabaseSessionHandlerListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public function handle($event): void
2121
if ($event instanceof WithApplication) {
2222
$app = $event->application();
2323

24+
if (!$app->resolved($session_abstract = 'session')) {
25+
return;
26+
}
27+
2428
/** @var \Illuminate\Session\SessionManager $session */
25-
$session = $app->make('session');
29+
$session = $app->make($session_abstract);
2630
$driver = $session->driver();
2731

2832
if ($driver instanceof \Illuminate\Contracts\Session\Session) {

src/Listeners/RebindHttpKernelListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ public function handle($event): void
2323
if ($event instanceof WithApplication) {
2424
$app = $event->application();
2525

26+
if (!$app->resolved($kernel_abstract = HttpKernel::class)) {
27+
return;
28+
}
29+
2630
/** @var HttpKernel $kernel */
27-
$kernel = $app->make(HttpKernel::class);
31+
$kernel = $app->make($kernel_abstract);
2832

2933
/**
3034
* Method `setApplication` for the HTTP kernel available since Laravel v8.35.0.

src/Listeners/RebindRouterListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ public function handle($event): void
2525
$app = $event->application();
2626
$request = $event->httpRequest();
2727

28+
if (!$app->resolved($router_abstract = 'router')) {
29+
return;
30+
}
31+
2832
/** @var \Illuminate\Routing\Router $router */
29-
$router = $app->make('router');
33+
$router = $app->make($router_abstract);
3034

3135
/**
3236
* Method `setContainer` for the Router available since Laravel v8.35.0.

src/Listeners/RebindViewListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ public function handle($event): void
2020
if ($event instanceof WithApplication) {
2121
$app = $event->application();
2222

23+
if (!$app->resolved($view_abstract = 'view')) {
24+
return;
25+
}
26+
2327
/** @var \Illuminate\View\Factory $view */
24-
$view = $app->make('view');
28+
$view = $app->make($view_abstract);
2529

2630
$view->setContainer($app);
2731
$view->share('app', $app);

0 commit comments

Comments
 (0)