Skip to content

Commit 22ccff5

Browse files
authored
New event listeners added (#40)
1 parent 2f67290 commit 22ccff5

File tree

68 files changed

+1725
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1725
-112
lines changed

.codecov.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Docs: <https://docs.codecov.io/docs/commit-status>
2+
3+
coverage:
4+
# coverage lower than 50 is red, higher than 90 green
5+
range: 30..80
6+
7+
status:
8+
project:
9+
default:
10+
# Choose a minimum coverage ratio that the commit must meet to be considered a success.
11+
#
12+
# `auto` will use the coverage from the base commit (pull request base or parent commit) coverage to compare
13+
# against.
14+
target: auto
15+
16+
# Allow the coverage to drop by X%, and posting a success status.
17+
threshold: 5%
18+
19+
# Resulting status will pass no matter what the coverage is or what other settings are specified.
20+
informational: true
21+
22+
patch:
23+
default:
24+
target: auto
25+
threshold: 5%
26+
informational: true

.github/workflows/tests.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
paths-ignore:
1313
- '**.md'
1414
schedule:
15-
- cron: '0 0 * * 0' # once in a week, docs: <https://git.io/JvxXE#onschedule>
15+
- cron: '0 0 * * 1' # once in a week, docs: <https://git.io/JvxXE#onschedule>
1616

1717
jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-actions>
1818
tests:
@@ -24,14 +24,17 @@ jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-ac
2424
matrix:
2525
setup: ['basic', 'lowest']
2626
php: ['7.4', '8.0']
27-
rr: ['2.0.1']
27+
rr: ['2.2.1'] # Releases: <https://github.com/spiral/roadrunner-binary/releases>
28+
coverage: ['true']
2829
include:
2930
- php: '7.4'
3031
setup: 'basic'
31-
coverage: 'true'
32+
rr: '2.0.0'
33+
coverage: 'false'
3234
- php: '8.0'
33-
setup: 'basic'
34-
coverage: 'true'
35+
setup: 'lowest'
36+
rr: '2.0.0'
37+
coverage: 'false'
3538
steps:
3639
- name: Check out code
3740
uses: actions/checkout@v2
@@ -43,7 +46,7 @@ jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-ac
4346
uses: shivammathur/setup-php@v2 # Action page: <https://github.com/shivammathur/setup-php>
4447
with:
4548
php-version: ${{ matrix.php }}
46-
extensions: mbstring, pdo, pdo_sqlite, sqlite3, xdebug # definition is required for php 7.4
49+
extensions: xdebug
4750

4851
- name: Get Composer Cache Directory # Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer>
4952
id: composer-cache
@@ -95,7 +98,6 @@ jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-ac
9598
uses: shivammathur/setup-php@v2
9699
with:
97100
php-version: 7.4
98-
extensions: mbstring
99101

100102
- name: Get Composer Cache Directory
101103
id: composer-cache

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ 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+
## UNRELEASED
8+
9+
### Added
10+
11+
- Listener `FlushArrayCacheListener` for flushing `array`-based cache storages
12+
- Listener `FlushAuthenticationStateListener` for authentication state flushing
13+
- Listener `RebindAuthorizationGateListener` for the authorization gate container rebinding
14+
- Listener `RebindBroadcastManagerListener` for the broadcast manager container rebinding
15+
- Listener `RebindDatabaseManagerListener` for the database manager container rebinding
16+
- Listener `RebindMailManagerListener` for the mail manager container rebinding and resolved mailer instances clearing
17+
- Listener `RebindNotificationChannelManagerListener` for the notification channel manager container rebinding and resolved driver instances clearing
18+
- Listener `RebindPipelineHubListener` for the pipeline hub container rebinding
19+
- Listener `RebindQueueManagerListener` for the queue manager container rebinding
20+
- Listener `RebindValidationFactoryListener` for the validator container rebinding
21+
- Listener `ResetDatabaseRecordModificationStateListener` for resetting the database record modification state
22+
- Listener `ResetLocaleStateListener` for the translator locale resetting
23+
- Integration with [inertiajs](https://inertiajs.com/) (package [inertiajs/inertia-laravel](https://github.com/inertiajs/inertia-laravel)) is supported now (just enable `ResetInertiaListener` for `BeforeLoopIterationEvent`)
24+
- Integration with [Laravel Scout](https://laravel.com/docs/master/scout/) is supported now (just enable `ResetLaravelScoutListener` for `BeforeLoopIterationEvent`)
25+
- Integration with [Laravel Socialite](https://github.com/laravel/socialite/) is supported now (just enable `ResetLaravelSocialiteListener` for `BeforeLoopIterationEvent`)
26+
27+
### Changed
28+
29+
- Listeners `RebindHttpKernelListener`, `RebindRouterListener`, `RebindViewListener` and `UnqueueCookiesListener` improved
30+
731
## v4.0.1
832

933
### Fixed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ FROM php:8.0-alpine
44
ENV COMPOSER_HOME="/tmp/composer"
55

66
# Image page: <https://hub.docker.com/_/composer>
7-
COPY --from=composer:2.0.11 /usr/bin/composer /usr/bin/composer
7+
COPY --from=composer:2.0.13 /usr/bin/composer /usr/bin/composer
88

99
# Image page: <https://hub.docker.com/r/spiralscout/roadrunner>
10-
COPY --from=spiralscout/roadrunner:2.0.1 /usr/bin/rr /usr/bin/rr
10+
COPY --from=spiralscout/roadrunner:2.2.1 /usr/bin/rr /usr/bin/rr
1111

1212
RUN set -x \
1313
&& apk add --no-cache binutils git \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img src="https://hsto.org/webt/xl/pr/89/xlpr891cyv9ux3gm7dtzwjse_5a.png" alt="logo" width="420" />
33
</p>
44

5-
# [RoadRunner][roadrunner] ⇆ Laravel bridge
5+
# [RoadRunner][roadrunner][Laravel][laravel] bridge
66

77
[![Version][badge_packagist_version]][link_packagist]
88
[![Version][badge_php_version]][link_packagist]

composer.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,39 @@
1616
],
1717
"require": {
1818
"php": "^7.4 || ^8.0",
19+
"composer-runtime-api": "^2.0",
20+
"illuminate/auth": "~6.0 || ~7.0 || ~8.0",
21+
"illuminate/broadcasting": "~6.0 || ~7.0 || ~8.0",
22+
"illuminate/cache": "~6.0 || ~7.0 || ~8.0",
1923
"illuminate/contracts": "~6.0 || ~7.0 || ~8.0",
20-
"illuminate/support": "~6.0 || ~7.0 || ~8.0",
24+
"illuminate/cookie": "~6.0 || ~7.0 || ~8.0",
25+
"illuminate/database": "~6.0 || ~7.0 || ~8.0",
2126
"illuminate/http": "~6.0 || ~7.0 || ~8.0",
27+
"illuminate/mail": "~6.0 || ~7.0 || ~8.0",
28+
"illuminate/notifications": "~6.0 || ~7.0 || ~8.0",
29+
"illuminate/pipeline": "~6.0 || ~7.0 || ~8.0",
30+
"illuminate/queue": "~6.0 || ~7.0 || ~8.0",
2231
"illuminate/routing": "~6.0 || ~7.0 || ~8.0",
23-
"spiral/roadrunner-worker": "^2.0",
24-
"spiral/roadrunner-http": "^2.0",
25-
"symfony/psr-http-message-bridge": "^1.2 || ^2.0",
32+
"illuminate/session": "~6.0 || ~7.0 || ~8.0",
33+
"illuminate/support": "~6.0 || ~7.0 || ~8.0",
34+
"illuminate/translation": "~6.0 || ~7.0 || ~8.0",
35+
"illuminate/validation": "~6.0 || ~7.0 || ~8.0",
36+
"illuminate/view": "~6.0 || ~7.0 || ~8.0",
2637
"laminas/laminas-diactoros": "^2",
38+
"spiral/roadrunner-http": "^2.0",
39+
"spiral/roadrunner-worker": "^2.0",
2740
"symfony/console": "^4.3.4 || ^5.0",
28-
"composer-runtime-api": "^2.0"
41+
"symfony/psr-http-message-bridge": "^1.2 || ^2.0"
2942
},
3043
"require-dev": {
44+
"guzzlehttp/guzzle": "^6.3 || ~7.0",
45+
"inertiajs/inertia-laravel": "^0.4.2",
3146
"laravel/laravel": "~6.0 || ~7.0 || ~8.0",
47+
"laravel/scout": "~8.0 || ~9.0",
48+
"laravel/socialite": "^5.0",
3249
"mockery/mockery": "^1.3.2",
3350
"phpstan/phpstan": "~0.12.80",
34-
"phpunit/phpunit": "^8.0 || ^9.3",
35-
"guzzlehttp/guzzle": "^6.3 || ~7.0"
51+
"phpunit/phpunit": "^8.0 || ^9.3"
3652
},
3753
"autoload": {
3854
"psr-4": {
@@ -48,7 +64,7 @@
4864
"bin/rr-worker"
4965
],
5066
"scripts": {
51-
"phpunit": "@php ./vendor/bin/phpunit --no-coverage --colors=always",
67+
"phpunit": "@php ./vendor/bin/phpunit --no-coverage",
5268
"phpunit-cover": "@php ./vendor/bin/phpunit",
5369
"phpstan": "@php ./vendor/bin/phpstan analyze -c ./phpstan.neon.dist --no-progress --ansi",
5470
"test": [

config/roadrunner.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,24 @@
2727
*/
2828

2929
'pre_resolving' => [
30-
'view',
31-
'files',
32-
'session',
33-
'session.store',
34-
'routes',
35-
'db',
36-
'db.factory',
30+
'auth',
3731
'cache',
3832
'cache.store',
3933
'config',
4034
'cookie',
35+
'db',
36+
'db.factory',
4137
'encrypter',
38+
'files',
4239
'hash',
40+
'log',
4341
'router',
42+
'routes',
43+
'session',
44+
'session.store',
4445
'translator',
4546
'url',
46-
'log',
47+
'view',
4748
],
4849

4950
/*
@@ -66,10 +67,24 @@
6667
Listeners\EnableHttpMethodParameterOverrideListener::class,
6768
Listeners\RebindHttpKernelListener::class, // Laravel 7 issue: <https://git.io/JvPpf>
6869
Listeners\RebindViewListener::class,
70+
Listeners\RebindAuthorizationGateListener::class,
71+
Listeners\RebindBroadcastManagerListener::class,
72+
Listeners\RebindDatabaseManagerListener::class,
73+
Listeners\RebindMailManagerListener::class,
74+
Listeners\RebindNotificationChannelManagerListener::class,
75+
Listeners\RebindPipelineHubListener::class,
76+
Listeners\RebindQueueManagerListener::class,
77+
Listeners\RebindValidationFactoryListener::class,
6978
Listeners\CloneConfigListener::class,
7079
Listeners\UnqueueCookiesListener::class,
80+
Listeners\FlushAuthenticationStateListener::class,
7181
Listeners\ResetSessionListener::class,
7282
Listeners\ResetProvidersListener::class,
83+
Listeners\ResetLocaleStateListener::class,
84+
85+
// Listeners\ResetLaravelScoutListener::class, // for 'laravel/scout' package
86+
// Listeners\ResetLaravelSocialiteListener::class, // for 'laravel/socialite' package
87+
// Listeners\ResetInertiaListener::class, // for 'inertiajs/inertia-laravel' package
7388
],
7489

7590
Events\BeforeRequestHandlingEvent::class => [
@@ -85,6 +100,8 @@
85100
],
86101

87102
Events\AfterLoopIterationEvent::class => [
103+
Listeners\FlushArrayCacheListener::class,
104+
Listeners\ResetDatabaseRecordModificationStateListener::class,
88105
Listeners\ClearInstancesListener::class,
89106
Listeners\RunGarbageCollectorListener::class,
90107
],
@@ -110,7 +127,7 @@
110127
*/
111128

112129
'clear_instances' => [
113-
'auth',
130+
'auth', // is not required for Laravel >= v8.35
114131
],
115132

116133
/*
@@ -124,8 +141,8 @@
124141
*/
125142

126143
'reset_providers' => [
127-
Illuminate\Auth\AuthServiceProvider::class,
144+
Illuminate\Auth\AuthServiceProvider::class, // is not required for Laravel >= v8.35
128145
// App\Your\Custom\AuthServiceProvider::class,
129-
Illuminate\Pagination\PaginationServiceProvider::class,
146+
Illuminate\Pagination\PaginationServiceProvider::class, // is not required for Laravel >= v8.35
130147
],
131148
];

phpstan.neon.dist

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,4 @@ parameters:
33
paths:
44
- src
55
- bin/rr-worker
6-
reportUnmatchedIgnoredErrors: false
7-
ignoreErrors:
8-
- message: '#Access to an undefined property.*::\$app#'
9-
paths: [src/Listeners/RebindHttpKernelListener.php]
10-
- message: '#Access to an undefined property.*::\$container#'
11-
paths: [src/Listeners/RebindRouterListener.php]
12-
- message: '#Access to an undefined property.*::\$(container|shared)#'
13-
paths: [src/Listeners/RebindViewListener.php]
6+
reportUnmatchedIgnoredErrors: true

phpunit.xml.dist

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
<testsuites>
88
<testsuite name="Unit">
9-
<directory suffix="Test.php">./tests/Unit</directory>
9+
<directory>./tests/Unit</directory>
1010
</testsuite>
1111
<testsuite name="Feature">
12-
<directory suffix="Test.php">./tests/Feature</directory>
12+
<directory>./tests/Feature</directory>
1313
</testsuite>
1414
</testsuites>
1515

@@ -22,10 +22,10 @@
2222
<directory>./tests</directory>
2323
</exclude>
2424
<report>
25-
<clover outputFile="./coverage/clover.xml"/>
2625
<html outputDirectory="./coverage/html"/>
27-
<text outputFile="php://stdout" showUncoveredFiles="false"/>
2826
<xml outputDirectory="./coverage/xml"/>
27+
<clover outputFile="./coverage/clover.xml"/>
28+
<text outputFile="php://stdout" showUncoveredFiles="false"/>
2929
</report>
3030
</coverage>
3131

@@ -36,6 +36,11 @@
3636
<log type="coverage-clover" target="./coverage/clover.xml"/>
3737
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
3838
</logging>
39+
<filter>
40+
<whitelist>
41+
<directory suffix=".php">./src</directory>
42+
</whitelist>
43+
</filter>
3944
<!-- /deprecated -->
4045

4146
<php>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\RoadRunnerLaravel\Listeners;
6+
7+
use Illuminate\Cache\CacheManager;
8+
use Spiral\RoadRunnerLaravel\Events\Contracts\WithApplication;
9+
use Illuminate\Contracts\Config\Repository as ConfigRepository;
10+
11+
/**
12+
* @link https://github.com/laravel/octane/blob/1.x/src/Listeners/FlushArrayCache.php
13+
*/
14+
class FlushArrayCacheListener 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+
/** @var ConfigRepository $config */
25+
$config = $app->make(ConfigRepository::class);
26+
27+
/** @var CacheManager $cache_manager */
28+
$cache_manager = $app->make('cache');
29+
30+
foreach ($config->get('cache.stores') as $name => $options) {
31+
if (($options['driver'] ?? '') === 'array') {
32+
$cache_manager->store($name)->getStore()->flush();
33+
}
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)