From b5309ec1fa221fb966b30b26f8652370441931b2 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 5 Jan 2025 19:02:53 -0500 Subject: [PATCH] Revert "Listen to more framework webhook events (#728)" This reverts commit 7a4c4ce02a8e55413ebee4c470a8245c1a767f1f. --- app/Models/WebhookConfiguration.php | 43 ++++--------------- app/Providers/EventServiceProvider.php | 2 - .../Feature/Webhooks/DispatchWebhooksTest.php | 15 ------- 3 files changed, 8 insertions(+), 52 deletions(-) diff --git a/app/Models/WebhookConfiguration.php b/app/Models/WebhookConfiguration.php index 309565bc62..cf792da195 100644 --- a/app/Models/WebhookConfiguration.php +++ b/app/Models/WebhookConfiguration.php @@ -34,24 +34,6 @@ class WebhookConfiguration extends Model 'events', ]; - public static function getEventClassesFromDirectory(string $directory, string $after): array - { - $events = []; - foreach (File::allFiles($directory) as $file) { - $namespace = str($file->getPath()) - ->after($after) - ->replace(DIRECTORY_SEPARATOR, '\\') - ->after('\\') - ->replaceFirst('app', 'App') - ->toString(); - - $events[] = $namespace.'\\'.str($file->getFilename()) - ->replace([DIRECTORY_SEPARATOR, '.php'], ['\\', '']); - } - - return $events; - } - protected function casts(): array { return [ @@ -93,7 +75,6 @@ public static function allPossibleEvents(): array { return collect(static::discoverCustomEvents()) ->merge(static::allModelEvents()) - ->merge(static::discoverFrameworkEvents()) ->unique() ->filter(fn ($event) => !in_array($event, static::$eventBlacklist)) ->all(); @@ -116,7 +97,6 @@ public static function transformClassName(string $event): string ->after('eloquent.') ->replace('App\\Models\\', '') ->replace('App\\Events\\', 'event: ') - ->replaceMatches('/Illuminate\\\\([A-z]+)\\\\Events\\\\/', fn (array $matches) => strtolower($matches[1]) . ': ') ->toString(); } @@ -153,23 +133,16 @@ public static function discoverCustomEvents(): array { $directory = app_path('Events'); - return self::getEventClassesFromDirectory($directory, base_path()); - } - - public static function discoverFrameworkEvents(): array - { - $frameworkDirectory = 'vendor/laravel/framework/src/'; - - $eventDirectories = [ - 'Illuminate/Auth/Events', - 'Illuminate/Queue/Events', - ]; - $events = []; - foreach ($eventDirectories as $eventDirectory) { - $directory = base_path("$frameworkDirectory/$eventDirectory"); + foreach (File::allFiles($directory) as $file) { + $namespace = str($file->getPath()) + ->after(base_path()) + ->replace(DIRECTORY_SEPARATOR, '\\') + ->replace('\\app\\', 'App\\') + ->toString(); - $events = array_merge($events, static::getEventClassesFromDirectory($directory, $frameworkDirectory)); + $events[] = $namespace . '\\' . str($file->getFilename()) + ->replace([DIRECTORY_SEPARATOR, '.php'], ['\\', '']); } return $events; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 284718d70c..50a6e42cdd 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -15,7 +15,5 @@ class EventServiceProvider extends ServiceProvider 'eloquent.created*' => [DispatchWebhooks::class], 'eloquent.deleted*' => [DispatchWebhooks::class], 'eloquent.updated*' => [DispatchWebhooks::class], - 'Illuminate\\Auth\\Events\\*' => [DispatchWebhooks::class], - 'Illuminate\\Queue\\Events\\*' => [DispatchWebhooks::class], ]; } diff --git a/tests/Feature/Webhooks/DispatchWebhooksTest.php b/tests/Feature/Webhooks/DispatchWebhooksTest.php index 89b89f99c6..7fcb1e326d 100644 --- a/tests/Feature/Webhooks/DispatchWebhooksTest.php +++ b/tests/Feature/Webhooks/DispatchWebhooksTest.php @@ -4,12 +4,9 @@ use App\Jobs\ProcessWebhook; use App\Models\Server; -use App\Models\User; use App\Models\WebhookConfiguration; use App\Tests\TestCase; -use Illuminate\Auth\Events\Authenticated; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; -use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Queue; class DispatchWebhooksTest extends TestCase @@ -91,18 +88,6 @@ public function test_it_does_not_call_deleted_webhooks() Queue::assertNothingPushed(); } - public function test_it_listens_to_framework_events() - { - WebhookConfiguration::factory()->create([ - 'events' => [Authenticated::class], - ]); - - $user = User::factory()->create(); - Auth::login($user); - - Queue::assertPushed(ProcessWebhook::class, 1); - } - public function createServer(): Server { return Server::factory()->withNode()->create();