Skip to content

Commit afda801

Browse files
authored
Merge pull request #2012 from brefphp/remove-deprecated-hooks
Remove the deprecated "hooks" system
2 parents e6f6c6e + 9fe6e06 commit afda801

9 files changed

Lines changed: 0 additions & 137 deletions

File tree

src/Bref.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class Bref
1212
{
1313
private static ?Closure $containerProvider = null;
1414
private static ?ContainerInterface $container = null;
15-
/** @deprecated Use Bref::events()->subscribe() instead */
16-
private static array $hooks = [
17-
'beforeStartup' => [],
18-
'beforeInvoke' => [],
19-
];
2015
private static EventDispatcher $eventDispatcher;
2116

2217
/**
@@ -37,46 +32,6 @@ public static function events(): EventDispatcher
3732
return self::$eventDispatcher;
3833
}
3934

40-
/**
41-
* Register a hook to be executed before the runtime starts.
42-
*
43-
* Warning: hooks are low-level extension points to be used by framework
44-
* integrations. For user code, it is not recommended to use them. Use your
45-
* framework's extension points instead.
46-
*
47-
* @deprecated Use Bref::events()->subscribe() instead.
48-
*/
49-
public static function beforeStartup(Closure $hook): void
50-
{
51-
self::$hooks['beforeStartup'][] = $hook;
52-
}
53-
54-
/**
55-
* Register a hook to be executed before any Lambda invocation.
56-
*
57-
* Warning: hooks are low-level extension points to be used by framework
58-
* integrations. For user code, it is not recommended to use them. Use your
59-
* framework's extension points instead.
60-
*
61-
* @deprecated Use Bref::events()->subscribe() instead.
62-
*/
63-
public static function beforeInvoke(Closure $hook): void
64-
{
65-
self::$hooks['beforeInvoke'][] = $hook;
66-
}
67-
68-
/**
69-
* @param 'beforeStartup'|'beforeInvoke' $hookName
70-
*
71-
* @internal Used by the Bref runtime
72-
*/
73-
public static function triggerHooks(string $hookName): void
74-
{
75-
foreach (self::$hooks[$hookName] as $hook) {
76-
$hook();
77-
}
78-
}
79-
8035
/**
8136
* @internal Used by the Bref runtime
8237
*/
@@ -103,10 +58,6 @@ public static function reset(): void
10358
{
10459
self::$containerProvider = null;
10560
self::$container = null;
106-
self::$hooks = [
107-
'beforeStartup' => [],
108-
'beforeInvoke' => [],
109-
];
11061
self::$eventDispatcher = new EventDispatcher;
11162
}
11263
}

src/ConsoleRuntime/Main.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static function run(): void
2020

2121
LazySecretsLoader::loadSecretEnvironmentVariables();
2222

23-
Bref::triggerHooks('beforeStartup');
2423
Bref::events()->beforeStartup();
2524

2625
$lambdaRuntime = LambdaRuntime::fromEnvironmentVariable('console');

src/FpmRuntime/Main.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static function run(): void
2020

2121
LazySecretsLoader::loadSecretEnvironmentVariables();
2222

23-
Bref::triggerHooks('beforeStartup');
2423
Bref::events()->beforeStartup();
2524

2625
$lambdaRuntime = LambdaRuntime::fromEnvironmentVariable('fpm');

src/FunctionRuntime/Main.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public static function run(): void
1919

2020
LazySecretsLoader::loadSecretEnvironmentVariables();
2121

22-
Bref::triggerHooks('beforeStartup');
2322
Bref::events()->beforeStartup();
2423

2524
$lambdaRuntime = LambdaRuntime::fromEnvironmentVariable('function');

src/Runtime/LambdaRuntime.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public function processNextEvent(Handler | RequestHandlerInterface | callable $h
8888
try {
8989
ColdStartTracker::invocationStarted();
9090

91-
Bref::triggerHooks('beforeInvoke');
9291
Bref::events()->beforeInvoke($handler, $event, $context);
9392

9493
$this->ping();

tests/BrefTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,4 @@ public function test override the container(): void
3030

3131
$this->assertSame($container, Bref::getContainer());
3232
}
33-
34-
public function test hooks(): void
35-
{
36-
$beforeStartup1 = false;
37-
$beforeStartup2 = false;
38-
$beforeInvoke = false;
39-
40-
// Check that we can set multiple handlers
41-
Bref::beforeStartup(function () use (&$beforeStartup1) {
42-
return $beforeStartup1 = true;
43-
});
44-
Bref::beforeStartup(function () use (&$beforeStartup2) {
45-
return $beforeStartup2 = true;
46-
});
47-
Bref::beforeInvoke(function () use (&$beforeInvoke) {
48-
return $beforeInvoke = true;
49-
});
50-
51-
$this->assertFalse($beforeStartup1);
52-
$this->assertFalse($beforeStartup2);
53-
$this->assertFalse($beforeInvoke);
54-
55-
Bref::triggerHooks('beforeStartup');
56-
$this->assertTrue($beforeStartup1);
57-
$this->assertTrue($beforeStartup2);
58-
$this->assertFalse($beforeInvoke);
59-
60-
Bref::triggerHooks('beforeInvoke');
61-
$this->assertTrue($beforeInvoke);
62-
}
6333
}

tests/ConsoleRuntime/MainTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace Bref\Test\ConsoleRuntime;
44

5-
use Bref\Bref;
65
use Bref\ConsoleRuntime\CommandFailed;
76
use Bref\ConsoleRuntime\Main;
87
use Bref\Test\RuntimeTestCase;
98
use Bref\Test\Server;
10-
use Exception;
119

1210
class MainTest extends RuntimeTestCase
1311
{
@@ -19,16 +17,6 @@ public function setUp(): void
1917
putenv('_HANDLER=console.php');
2018
}
2119

22-
public function test startup hook is called()
23-
{
24-
Bref::beforeStartup(function () {
25-
throw new Exception('This should be called');
26-
});
27-
28-
$this->expectExceptionMessage('This should be called');
29-
Main::run();
30-
}
31-
3220
public function test happy path()
3321
{
3422
$this->givenAnEvent('');

tests/FpmRuntime/MainTest.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/FunctionRuntime/MainTest.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)