Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Resolve components when needed (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam authored Aug 13, 2021
1 parent a853329 commit bf3f612
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

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

## v5.2.2

### Changed

- Resolve listener components when needed [#58]

[#58]:https://github.com/spiral/roadrunner-laravel/issues/58

## v5.2.1

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/FlushArrayCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if (! $app->resolved($cache_abstract = 'cache')) {
return;
}

/** @var ConfigRepository $config */
$config = $app->make(ConfigRepository::class);

/** @var CacheManager $cache_manager */
$cache_manager = $app->make('cache');
$cache_manager = $app->make($cache_abstract);

foreach ($config->get('cache.stores') as $name => $options) {
if (($options['driver'] ?? '') === 'array') {
Expand Down
10 changes: 8 additions & 2 deletions src/Listeners/FlushAuthenticationStateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ public function handle($event): void
$app = $event->application();

if ($app instanceof \Illuminate\Container\Container) {
$app->forgetInstance('auth.driver');
if ($app->resolved($auth_driver_abstract = 'auth.driver')) {
$app->forgetInstance($auth_driver_abstract);
}
}

if (! $app->resolved($auth_abstract = 'auth')) {
return;
}

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

/**
* Method `setApplication` for the Auth Manager available since Laravel v8.35.0.
Expand Down
9 changes: 5 additions & 4 deletions src/Listeners/ForceHttpsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public function handle($event): void
$config = $app->make(ConfigRepository::class);

if ((bool) $config->get(ServiceProvider::getConfigRootKey() . '.force_https', false)) {
/** @var UrlGenerator $url_generator */
$url_generator = $app->make(UrlGenerator::class);

$url_generator->forceScheme('https');
if ($app->resolved($url_generator_abstract = UrlGenerator::class)) {
/** @var UrlGenerator $url_generator */
$url_generator = $app->make($url_generator_abstract);
$url_generator->forceScheme('https');
}

// Set 'HTTPS' server parameter (required for correct working request methods like ::isSecure
// and others)
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/RebindAuthorizationGateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if (! $app->resolved($gate_abstract = Gate::class)) {
return;
}

/** @var Gate $gate */
$gate = $app->make(Gate::class);
$gate = $app->make($gate_abstract);

/**
* Method `setContainer` for the Gate implementation available since Laravel v8.35.0.
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/RebindBroadcastManagerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if (! $app->resolved($broadcast_manager_abstract = BroadcastManager::class)) {
return;
}

/** @var BroadcastManager $broadcast_manager */
$broadcast_manager = $app->make(BroadcastManager::class);
$broadcast_manager = $app->make($broadcast_manager_abstract);

/**
* Method `setApplication` for the BroadcastManager available since Laravel v8.35.0.
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/RebindDatabaseSessionHandlerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if (!$app->resolved($session_abstract = 'session')) {
return;
}

/** @var \Illuminate\Session\SessionManager $session */
$session = $app->make('session');
$session = $app->make($session_abstract);
$driver = $session->driver();

if ($driver instanceof \Illuminate\Contracts\Session\Session) {
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/RebindHttpKernelListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if (!$app->resolved($kernel_abstract = HttpKernel::class)) {
return;
}

/** @var HttpKernel $kernel */
$kernel = $app->make(HttpKernel::class);
$kernel = $app->make($kernel_abstract);

/**
* Method `setApplication` for the HTTP kernel available since Laravel v8.35.0.
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/RebindRouterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ public function handle($event): void
$app = $event->application();
$request = $event->httpRequest();

if (!$app->resolved($router_abstract = 'router')) {
return;
}

/** @var \Illuminate\Routing\Router $router */
$router = $app->make('router');
$router = $app->make($router_abstract);

/**
* Method `setContainer` for the Router available since Laravel v8.35.0.
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/RebindViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if (!$app->resolved($view_abstract = 'view')) {
return;
}

/** @var \Illuminate\View\Factory $view */
$view = $app->make('view');
$view = $app->make($view_abstract);

$view->setContainer($app);
$view->share('app', $app);
Expand Down
4 changes: 2 additions & 2 deletions src/Listeners/ResetLocaleStateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public function handle($event): void
if ($event instanceof WithApplication) {
$app = $event->application();

if ($app->bound('translator')) {
if ($app->bound($translator_abstract = 'translator')) {
/** @var ConfigRepository $config */
$config = $app->make(ConfigRepository::class);

/** @var Translator $translator */
$translator = $app->make('translator');
$translator = $app->make($translator_abstract);

$translator->setLocale($config->get('app.locale'));

Expand Down

0 comments on commit bf3f612

Please sign in to comment.