Skip to content

Commit

Permalink
allow event discovery to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 29, 2024
1 parent aa22a81 commit 978ee88
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ public function withProviders(array $providers = [], bool $withBootstrapProvider
/**
* Register the core event service provider for the application.
*
* @param array $discover
* @param array|bool $discover
* @return $this
*/
public function withEvents(array $discover = [])
public function withEvents(array|bool $discover = [])
{
if (count($discover) > 0) {
if (is_array($discover) && count($discover) > 0) {
AppEventServiceProvider::setEventDiscoveryPaths($discover);
}

if ($discover === false) {
AppEventServiceProvider::disableEventDiscovery();
}

if (! isset($this->pendingProviders[AppEventServiceProvider::class])) {
$this->app->booting(function () {
$this->app->register(AppEventServiceProvider::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class EventServiceProvider extends ServiceProvider
*/
protected $observers = [];

/**
* Indiates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;

/**
* The configured event discovery paths.
*
Expand Down Expand Up @@ -127,7 +134,7 @@ protected function discoveredEvents()
*/
public function shouldDiscoverEvents()
{
return get_class($this) === __CLASS__;
return get_class($this) === __CLASS__ && static::$shouldDiscoverEvents === true;
}

/**
Expand Down Expand Up @@ -182,6 +189,16 @@ protected function eventDiscoveryBasePath()
return base_path();
}

/**
* Disable event discovery for the application.
*
* @return void
*/
public static function disableEventDiscovery()
{
static::$shouldDiscoverEvents = false;
}

/**
* Configure the proper event listeners for email verification.
*
Expand Down

0 comments on commit 978ee88

Please sign in to comment.