Skip to content

Commit 0ef240a

Browse files
committed
Add support for Laravel 12
1 parent 3277454 commit 0ef240a

File tree

8 files changed

+135
-107
lines changed

8 files changed

+135
-107
lines changed

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: '8.1'
21+
php-version: '8.4'
2222
coverage: none
2323

2424
- name: Install composer dependencies

.github/workflows/run-tests.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@ jobs:
1717
fail-fast: true
1818
matrix:
1919
os: [ ubuntu-latest ] # [..., windows-latest ]
20-
php: [8.3, 8.2, 8.1]
21-
laravel: [ 10, 11 ]
22-
stability: [ prefer-stable ]
20+
php: [ 8.1, 8.2, 8.3, 8.4 ]
21+
laravel: [ 10.*,11.*,12.* ]
22+
stability: [ prefer-lowest, prefer-stable ]
2323
include:
24-
- laravel: 10
25-
testbench: 8.*
26-
carbon: "^2.72.2|^3.0"
27-
- laravel: 11
24+
- laravel: 12.*
25+
testbench: 10.*
26+
- laravel: 11.*
2827
testbench: 9.*
29-
carbon: "^2.72.2|^3.0"
28+
- laravel: 10.*
29+
testbench: 8.*
3030
exclude:
3131
- php: 8.1
32-
laravel: 11
32+
laravel: 11.*
33+
- php: 8.1
34+
laravel: 12.*
3335

3436
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
3537

@@ -51,7 +53,7 @@ jobs:
5153
5254
- name: Install dependencies
5355
run: |
54-
composer require "laravel/framework:${{ matrix.laravel }}.*" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
56+
composer require "laravel/framework:${{ matrix.laravel }}.*" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
5557
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
5658
5759
- name: List Installed Dependencies
@@ -68,13 +70,13 @@ jobs:
6870
if-no-files-found: ignore
6971
retention-days: 1
7072

71-
# - name: Publish Test Results
72-
# uses: mikepenz/action-junit-report@v5
73-
# if: always()
74-
# with:
75-
# report_paths: 'build/**.junit.xml'
76-
# include_passed: true
77-
# follow_symlink: true
73+
- name: Publish Test Results
74+
uses: mikepenz/action-junit-report@v5
75+
if: always()
76+
with:
77+
report_paths: 'build/**.junit.xml'
78+
include_passed: true
79+
follow_symlink: true
7880

7981
process-test-data:
8082
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ___
1313
## Requirements
1414

1515
* PHP >= 8.1
16-
* Laravel 10.x|11.x
16+
* Laravel 10.x|11.x|12.x
1717

1818
## Installation
1919

composer.json

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,81 @@
11
{
2-
"name": "quix-labs/laravel-hook-system",
3-
"description": "Add hooks system to Laravel",
4-
"type": "library",
5-
"license": "MIT",
6-
"keywords": [
7-
"laravel",
8-
"hook",
9-
"interceptor"
10-
],
11-
"authors": [
12-
{
13-
"name": "COLANT Alan",
14-
"email": "contact@alancolant.com",
15-
"role": "Developer"
16-
}
17-
],
18-
"require": {
19-
"illuminate/support": "^10.0|^11.0",
20-
"illuminate/contracts": "^10.0|^11.0",
21-
"illuminate/console": "^10.0|^11.0"
22-
},
23-
"require-dev": {
24-
"larastan/larastan": "^2.9",
25-
"laravel/pint": "^1.14",
26-
"nunomaduro/collision": "^8.1.1||^7.10.0",
27-
"orchestra/testbench": "^9.0.0||^8.22.0",
28-
"pestphp/pest": "^2.34",
29-
"pestphp/pest-plugin-arch": "^2.7",
30-
"pestphp/pest-plugin-laravel": "^2.3",
31-
"phpstan/extension-installer": "^1.3",
32-
"phpstan/phpstan-deprecation-rules": "^1.1",
33-
"phpstan/phpstan-phpunit": "^1.3"
34-
},
35-
"autoload": {
36-
"psr-4": {
37-
"QuixLabs\\LaravelHookSystem\\": "src/"
38-
}
39-
},
40-
"autoload-dev": {
41-
"psr-4": {
42-
"QuixLabs\\LaravelHookSystem\\Tests\\": "tests/",
43-
"Workbench\\App\\": "workbench/app/"
44-
}
45-
},
46-
"scripts": {
47-
"post-autoload-dump": "@composer run prepare",
48-
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
49-
"prepare": "@php vendor/bin/testbench package:discover --ansi",
50-
"build": [
51-
"@composer run prepare",
52-
"@php vendor/bin/testbench workbench:build --ansi"
2+
"name": "quix-labs/laravel-hook-system",
3+
"description": "Add hooks system to Laravel",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"laravel",
8+
"hook",
9+
"interceptor"
5310
],
54-
"start": [
55-
"Composer\\Config::disableProcessTimeout",
56-
"@composer run build",
57-
"@php vendor/bin/testbench serve"
11+
"authors": [
12+
{
13+
"name": "COLANT Alan",
14+
"email": "contact@alancolant.com",
15+
"role": "Developer"
16+
}
5817
],
59-
"analyse": "vendor/bin/phpstan analyse --memory-limit=1G",
60-
"test": "vendor/bin/pest",
61-
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/pest --coverage",
62-
"format": "vendor/bin/pint"
63-
},
64-
"config": {
65-
"sort-packages": true,
66-
"allow-plugins": {
67-
"pestphp/pest-plugin": true,
68-
"phpstan/extension-installer": true
69-
}
70-
},
71-
"extra": {
72-
"laravel": {
73-
"providers": [
74-
"QuixLabs\\LaravelHookSystem\\Providers\\ServiceProvider"
75-
]
76-
}
77-
},
78-
"minimum-stability": "dev",
79-
"prefer-stable": true
18+
"require": {
19+
"php": "^8.1",
20+
"illuminate/support": "^10.0 || ^11.0 || ^12.0",
21+
"illuminate/contracts": "^10.0 || ^11.0 || ^12.0",
22+
"illuminate/console": "^10.0 || ^11.0 || ^12.0"
23+
},
24+
"require-dev": {
25+
"larastan/larastan": "^2.0.1 || ^3.0",
26+
"laravel/pint": "^1.14",
27+
"nunomaduro/collision": "^8.1.1||^7.10.0",
28+
"orchestra/testbench": "^8.8 || ^9.0 || ^10.0",
29+
"pestphp/pest": "^2.20 || ^3.0 ",
30+
"pestphp/pest-plugin-arch": "^2.0 || ^3.0",
31+
"pestphp/pest-plugin-laravel": "^2.0 || ^3.0",
32+
"phpstan/extension-installer": "^1.3",
33+
"phpstan/phpstan-deprecation-rules": "^1.1 || ^2.0",
34+
"phpstan/phpstan-phpunit": "^1.3 || ^2.0"
35+
},
36+
"autoload": {
37+
"psr-4": {
38+
"QuixLabs\\LaravelHookSystem\\": "src/"
39+
}
40+
},
41+
"autoload-dev": {
42+
"psr-4": {
43+
"QuixLabs\\LaravelHookSystem\\Tests\\": "tests/",
44+
"Workbench\\App\\": "workbench/app/"
45+
}
46+
},
47+
"scripts": {
48+
"post-autoload-dump": "@composer run prepare",
49+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
50+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
51+
"build": [
52+
"@composer run prepare",
53+
"@php vendor/bin/testbench workbench:build --ansi"
54+
],
55+
"start": [
56+
"Composer\\Config::disableProcessTimeout",
57+
"@composer run build",
58+
"@php vendor/bin/testbench serve"
59+
],
60+
"analyse": "vendor/bin/phpstan analyse --memory-limit=1G",
61+
"test": "vendor/bin/pest",
62+
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/pest --coverage",
63+
"format": "vendor/bin/pint"
64+
},
65+
"config": {
66+
"sort-packages": true,
67+
"allow-plugins": {
68+
"pestphp/pest-plugin": true,
69+
"phpstan/extension-installer": true
70+
}
71+
},
72+
"extra": {
73+
"laravel": {
74+
"providers": [
75+
"QuixLabs\\LaravelHookSystem\\Providers\\ServiceProvider"
76+
]
77+
}
78+
},
79+
"minimum-stability": "dev",
80+
"prefer-stable": true
8081
}

src/Console/Commands/HooksCacheCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Illuminate\Console\Command;
66
use QuixLabs\LaravelHookSystem\Facades\HookManager;
7+
use Symfony\Component\Console\Attribute\AsCommand;
78

9+
#[AsCommand("hooks:cache")]
810
class HooksCacheCommand extends Command
911
{
1012
protected $signature = 'hooks:cache';

src/Console/Commands/HooksClearCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Illuminate\Console\Command;
66
use QuixLabs\LaravelHookSystem\Facades\HookManager;
7+
use Symfony\Component\Console\Attribute\AsCommand;
78

9+
#[AsCommand("hooks:clear")]
810
class HooksClearCommand extends Command
911
{
1012
protected $signature = 'hooks:clear';
@@ -14,7 +16,7 @@ class HooksClearCommand extends Command
1416
public function handle(): int
1517
{
1618
HookManager::clearCache();
17-
if (! HookManager::isCached()) {
19+
if (!HookManager::isCached()) {
1820
$this->components->info('Compiled hooks cleared successfully.');
1921
}
2022

src/Console/Commands/HooksStatusCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use QuixLabs\LaravelHookSystem\Hook;
88
use QuixLabs\LaravelHookSystem\Hooks\GetHooksTable;
99
use QuixLabs\LaravelHookSystem\Utils\CommandTable;
10+
use Symfony\Component\Console\Attribute\AsCommand;
1011

12+
#[AsCommand("hooks:status")]
1113
class HooksStatusCommand extends Command
1214
{
1315
protected $signature = 'hooks:status';
@@ -21,23 +23,23 @@ public function handle(): int
2123
}
2224

2325
$hooks = collect(HookManager::getHooks())
24-
->mapWithKeys(fn (string|Hook $hook) => [$hook => HookManager::getInterceptorsForHook($hook)])->toArray();
26+
->mapWithKeys(fn(string|Hook $hook) => [$hook => HookManager::getInterceptorsForHook($hook)])->toArray();
2527
$rows = collect($hooks)->map(function (array $interceptors, string $hookClass) {
2628
$callables = collect($interceptors)
27-
->map(fn (array $callables, int $priority) => implode('<br/>', array_map(
28-
fn (callable $callable) => static::_callableToString($callable), $callables)
29+
->map(fn(array $callables, int $priority) => implode('<br/>', array_map(
30+
fn(callable $callable) => static::_callableToString($callable), $callables)
2931
))->join('<br/>');
3032

3133
$priorities = collect($interceptors)
32-
->map(fn (array $callables, int $priority) => implode('<br/>', array_fill(0, count($callables), $priority)))
34+
->map(fn(array $callables, int $priority) => implode('<br/>', array_fill(0, count($callables), $priority)))
3335
->join('<br/>');
3436

3537
return [
36-
'Hook' => $hookClass,
37-
'Interceptors' => $callables,
38-
'Priority' => $priorities,
38+
'Hook' => $hookClass,
39+
'Interceptors' => $callables,
40+
'Priority' => $priorities,
3941
'Fully Cacheable' => HookManager::isFullyCacheable($hookClass) ? 'YES' : 'NO',
40-
'Fully Cached' => HookManager::isFullyCached($hookClass) ? 'YES' : 'NO',
42+
'Fully Cached' => HookManager::isFullyCached($hookClass) ? 'YES' : 'NO',
4143
];
4244
})->toArray();
4345

src/Providers/ServiceProvider.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function boot(): void
2626
{
2727
$this->_bootHooksRegistry();
2828
$this->_appendInformationToAboutCommand();
29+
$this->_registerOptimizes();
2930
}
3031

3132
private function _registerHooks(): void
@@ -46,10 +47,11 @@ private function _registerCommands(): void
4647

4748
private function _appendInformationToAboutCommand(): void
4849
{
49-
if (! $this->app->runningInConsole()) {
50+
if (!$this->app->runningInConsole()) {
5051
return;
5152
}
52-
AboutCommand::add('Cache', fn () => [
53+
54+
AboutCommand::add('Cache', fn() => [
5355
'Hooks' => HookManagerFacade::isCached()
5456
? '<fg=green;options=bold>CACHED</>'
5557
: '<fg=yellow;options=bold>NOT CACHED</>',
@@ -58,7 +60,7 @@ private function _appendInformationToAboutCommand(): void
5860

5961
private function _bootHooksRegistry(): void
6062
{
61-
if (! HookManagerFacade::isCached()) {
63+
if (!HookManagerFacade::isCached()) {
6264
foreach (HookRegistry::getHooks() as $hook) {
6365
HookManagerFacade::registerHook($hook);
6466
}
@@ -68,4 +70,21 @@ private function _bootHooksRegistry(): void
6870
}
6971
HookRegistry::clear();
7072
}
73+
74+
private function _registerOptimizes(): void
75+
{
76+
if (!$this->app->runningInConsole()) {
77+
return;
78+
}
79+
80+
if (!method_exists($this, 'optimizes')) {
81+
return;
82+
}
83+
84+
$this->optimizes(
85+
optimize: HooksCacheCommand::getDefaultName(),
86+
clear: HooksClearCommand::getDefaultName(),
87+
key: 'hooks'
88+
);
89+
}
7190
}

0 commit comments

Comments
 (0)