Revert "Listen to more framework webhook events (#728)" (#866)

This reverts commit 7a4c4ce02a8e55413ebee4c470a8245c1a767f1f.
This commit is contained in:
Charles 2025-01-05 19:07:01 -05:00 committed by GitHub
parent 7cc4358a04
commit 2525af8f02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 52 deletions

View File

@ -34,24 +34,6 @@ class WebhookConfiguration extends Model
'events', '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 protected function casts(): array
{ {
return [ return [
@ -93,7 +75,6 @@ class WebhookConfiguration extends Model
{ {
return collect(static::discoverCustomEvents()) return collect(static::discoverCustomEvents())
->merge(static::allModelEvents()) ->merge(static::allModelEvents())
->merge(static::discoverFrameworkEvents())
->unique() ->unique()
->filter(fn ($event) => !in_array($event, static::$eventBlacklist)) ->filter(fn ($event) => !in_array($event, static::$eventBlacklist))
->all(); ->all();
@ -116,7 +97,6 @@ class WebhookConfiguration extends Model
->after('eloquent.') ->after('eloquent.')
->replace('App\\Models\\', '') ->replace('App\\Models\\', '')
->replace('App\\Events\\', 'event: ') ->replace('App\\Events\\', 'event: ')
->replaceMatches('/Illuminate\\\\([A-z]+)\\\\Events\\\\/', fn (array $matches) => strtolower($matches[1]) . ': ')
->toString(); ->toString();
} }
@ -153,23 +133,16 @@ class WebhookConfiguration extends Model
{ {
$directory = app_path('Events'); $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 = []; $events = [];
foreach ($eventDirectories as $eventDirectory) { foreach (File::allFiles($directory) as $file) {
$directory = base_path("$frameworkDirectory/$eventDirectory"); $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; return $events;

View File

@ -15,7 +15,5 @@ class EventServiceProvider extends ServiceProvider
'eloquent.created*' => [DispatchWebhooks::class], 'eloquent.created*' => [DispatchWebhooks::class],
'eloquent.deleted*' => [DispatchWebhooks::class], 'eloquent.deleted*' => [DispatchWebhooks::class],
'eloquent.updated*' => [DispatchWebhooks::class], 'eloquent.updated*' => [DispatchWebhooks::class],
'Illuminate\\Auth\\Events\\*' => [DispatchWebhooks::class],
'Illuminate\\Queue\\Events\\*' => [DispatchWebhooks::class],
]; ];
} }

View File

@ -4,12 +4,9 @@ namespace App\Tests\Feature\Webhooks;
use App\Jobs\ProcessWebhook; use App\Jobs\ProcessWebhook;
use App\Models\Server; use App\Models\Server;
use App\Models\User;
use App\Models\WebhookConfiguration; use App\Models\WebhookConfiguration;
use App\Tests\TestCase; use App\Tests\TestCase;
use Illuminate\Auth\Events\Authenticated;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
class DispatchWebhooksTest extends TestCase class DispatchWebhooksTest extends TestCase
@ -91,18 +88,6 @@ class DispatchWebhooksTest extends TestCase
Queue::assertNothingPushed(); 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 public function createServer(): Server
{ {
return Server::factory()->withNode()->create(); return Server::factory()->withNode()->create();