$this->discoveredEvents()); return array_merge_recursive( $events, $this->listens() ); } /** * @copydoc \Illuminate\Foundation\Support\Providers\EventServiceProvider::shouldDiscoverEvents() */ public function shouldDiscoverEvents() { return true; } /** * @copydoc \Illuminate\Foundation\Support\Providers\EventServiceProvider::discoverEvents() */ public function discoverEvents() { // Adapt classes naming convention $discoverEvents = new class () extends DiscoverEvents { /** * @copydoc \Illuminate\Foundation\Events\DiscoverEvents::classFromFile() */ protected static function classFromFile(SplFileInfo $file, $basePath): string { return Core::classFromFile($file); } }; return collect($this->discoverEventsWithin()) ->reject(function ($directory) { return !is_dir($directory); }) ->reduce(function ($discovered, $directory) use ($discoverEvents) { return array_merge_recursive( $discovered, $discoverEvents::within($directory, base_path()) ); }, []); } /** * @copydoc \Illuminate\Foundation\Support\Providers\EventServiceProvider::discoverEventsWithin() */ protected function discoverEventsWithin() { return [ $this->app->basePath('lib/pkp/classes/observers/listeners'), $this->app->basePath('classes/observers/listeners'), ]; } /** * Clears the event cache */ public static function clearCache(): void { Cache::forget(static::getCacheKey()); } /** * Retrieves a unique and static key to store the event cache */ private static function getCacheKey(): string { return __METHOD__ . static::MAX_CACHE_LIFETIME; } }