Skip to content

Commit 99d2205

Browse files
authored
chore: Code cleanup (#112)
1 parent 9edbcb8 commit 99d2205

27 files changed

+131
-234
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ 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.11.0
8+
9+
### Added
10+
11+
- Listener `FlushDatabaseQueryDurationListener` [#112]
12+
- Listener `RebindPaginatorListener` [#112]
13+
14+
### Changed
15+
16+
- Methods invoking in listeners replaced with normal function calls [#112]
17+
18+
[#112]:https://github.com/spiral/roadrunner-laravel/pull/112
19+
720
## v5.10.0
821

922
### Added

src/Defaults.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static function beforeLoopIteration(): array
4545
Listeners\RebindPipelineHubListener::class,
4646
Listeners\RebindQueueManagerListener::class,
4747
Listeners\RebindValidationFactoryListener::class,
48+
Listeners\RebindPaginatorListener::class,
4849
Listeners\UnqueueCookiesListener::class,
4950
Listeners\FlushAuthenticationStateListener::class,
5051
Listeners\ResetSessionListener::class,
@@ -102,6 +103,7 @@ public static function afterLoopIteration(): array
102103
Listeners\FlushTranslatorCacheListener::class,
103104
Listeners\ResetDatabaseRecordModificationStateListener::class,
104105
Listeners\FlushDatabaseQueryLogListener::class,
106+
Listeners\FlushDatabaseQueryDurationListener::class,
105107
Listeners\ClearInstancesListener::class,
106108
];
107109
}

src/Listeners/ClearInstancesListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function handle($event): void
2323
$app = $event->application();
2424

2525
if ($app instanceof Container) {
26+
$app->forgetScopedInstances();
27+
2628
/** @var ConfigRepository $config */
2729
$config = $app->make(ConfigRepository::class);
2830

src/Listeners/FlushAuthenticationStateListener.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,8 @@ public function handle($event): void
3434
/** @var \Illuminate\Auth\AuthManager $auth */
3535
$auth = $app->make($auth_abstract);
3636

37-
/**
38-
* Method `setApplication` for the Auth Manager available since Laravel v8.35.0.
39-
*
40-
* @link https://git.io/JsgTx Source code (v8.35.0)
41-
* @see \Illuminate\Auth\AuthManager::setApplication()
42-
*/
43-
if (! $this->invokeMethod($auth, 'setApplication', $app)) {
44-
$this->setProperty($auth, 'app', $app);
45-
}
46-
47-
/**
48-
* Method `forgetGuards` for the Auth Manager available since Laravel v8.35.0.
49-
*
50-
* @link https://git.io/Jsgkt Source code (v8.35.0)
51-
* @see \Illuminate\Auth\AuthManager::forgetGuards()
52-
*/
53-
if (! $this->invokeMethod($auth, 'forgetGuards')) {
54-
$this->setProperty($auth, 'guards', []);
55-
}
37+
$auth->setApplication($app);
38+
$auth->forgetGuards();
5639
}
5740
}
5841
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\RoadRunnerLaravel\Listeners;
6+
7+
use Illuminate\Database\Connection;
8+
use Illuminate\Database\DatabaseManager;
9+
use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication;
10+
11+
/**
12+
* @link https://github.com/laravel/octane/blob/1.x/src/Listeners/RefreshQueryDurationHandling.php
13+
*/
14+
class FlushDatabaseQueryDurationListener implements ListenerInterface
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function handle($event): void
20+
{
21+
if ($event instanceof WithApplication) {
22+
$app = $event->application();
23+
24+
if (!$app->resolved($database_abstract = 'db')) {
25+
return;
26+
}
27+
28+
/** @var DatabaseManager $database_manager */
29+
$database_manager = $app->make($database_abstract);
30+
31+
foreach ($database_manager->getConnections() as $connection) {
32+
if ($connection instanceof Connection) {
33+
$connection->resetTotalQueryDuration();
34+
$connection->allowQueryDurationHandlersToRunAgain();
35+
}
36+
}
37+
}
38+
}
39+
}

src/Listeners/FlushLogContextListener.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,11 @@ public function handle($event): void
2828
/** @var \Illuminate\Log\LogManager $log_manager */
2929
$log_manager = $app->make($log_abstract);
3030

31-
/** @var \Psr\Log\LoggerInterface|\Illuminate\Log\Logger $logger */
32-
$logger = $log_manager->driver();
33-
34-
/**
35-
* Method `withoutContext` for the Logger available since Laravel v8.49.0.
36-
*
37-
* @link https://github.com/illuminate/log/blob/v8.49.0/Logger.php#L202-L212 Source code (v8.49.0)
38-
* @see \Illuminate\Log\Logger::withoutContext
39-
*/
40-
$this->invokeMethod($logger, 'withoutContext');
31+
$log_manager->flushSharedContext();
32+
33+
if (($logger = $log_manager->driver()) instanceof \Illuminate\Log\Logger) {
34+
$logger->withoutContext();
35+
}
4136
}
4237
}
4338
}

src/Listeners/FlushStrCacheListener.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ class FlushStrCacheListener implements ListenerInterface
1818
*/
1919
public function handle($event): void
2020
{
21-
/**
22-
* Method `flushCache` for the Str available since Laravel v8.81.0.
23-
*
24-
* @link https://github.com/illuminate/support/blob/v8.81.0/Str.php#L994
25-
* @see \Illuminate\Support\Str::flushCache
26-
*/
27-
if (! $this->invokeStaticMethod($class = Str::class, 'flushCache')) {
28-
foreach (['snakeCache', 'camelCache', 'studlyCache'] as $property) {
29-
$this->setStaticProperty($class, $property, []);
30-
}
31-
}
21+
Str::flushCache();
3222
}
3323
}

src/Listeners/FlushTranslatorCacheListener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ public function handle($event): void
3131
$translator = $app->make($translator_abstract);
3232

3333
if ($translator instanceof NamespacedItemResolver) {
34-
/**
35-
* Method `flushParsedKeys` for the Translator available since Laravel v8.70.0.
36-
*
37-
* @link https://git.io/JXd0v Source code (v8.70.0)
38-
* @see Translator::flushParsedKeys()
39-
*/
40-
if (! $this->invokeMethod($translator, 'flushParsedKeys')) {
41-
$this->setProperty($translator, 'parsed', []);
42-
}
34+
$translator->flushParsedKeys();
4335
}
4436
}
4537
}

src/Listeners/RebindAuthorizationGateListener.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,10 @@ public function handle($event): void
2626
return;
2727
}
2828

29-
/** @var Gate $gate */
29+
/** @var \Illuminate\Auth\Access\Gate $gate */
3030
$gate = $app->make($gate_abstract);
3131

32-
/**
33-
* Method `setContainer` for the Gate implementation available since Laravel v8.35.0.
34-
*
35-
* @link https://git.io/JszTs Source code (v8.35.0)
36-
* @see \Illuminate\Auth\Access\Gate::setContainer
37-
*/
38-
if (! $this->invokeMethod($gate, 'setContainer', $app)) {
39-
$this->setProperty($gate, 'container', $app);
40-
}
32+
$gate->setContainer($app);
4133
}
4234
}
4335
}

src/Listeners/RebindBroadcastManagerListener.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@ public function handle($event): void
2929
/** @var BroadcastManager $broadcast_manager */
3030
$broadcast_manager = $app->make($broadcast_manager_abstract);
3131

32-
/**
33-
* Method `setApplication` for the BroadcastManager available since Laravel v8.35.0.
34-
*
35-
* @link https://git.io/Jszm3 Source code (v8.35.0)
36-
* @see \Illuminate\Broadcasting\BroadcastManager::setApplication
37-
*/
38-
if (! $this->invokeMethod($broadcast_manager, 'setApplication', $app)) {
39-
$this->setProperty($broadcast_manager, 'app', $app);
40-
}
32+
$broadcast_manager->setApplication($app);
4133

4234
// Forgetting drivers will flush all channel routes which is unwanted...
4335
// $broadcast_manager->forgetDrivers();

0 commit comments

Comments
 (0)