From aa2e7b6cb83b2efb1a4613f94431a1b1656db127 Mon Sep 17 00:00:00 2001 From: Tomas Ruud Date: Fri, 6 Sep 2019 20:35:58 +0200 Subject: [PATCH] [6.x] Prevent event autodiscovery from crashing when trying to instantiate files without classes (#29895) * Make sure event autodiscovery doesn't fail when trying to instantiate files that are not classes * Moving exception to comply with styles --- src/Illuminate/Foundation/Events/DiscoverEvents.php | 11 ++++++++--- .../Fixtures/EventDiscovery/Listeners/random.js | 0 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 tests/Integration/Foundation/Fixtures/EventDiscovery/Listeners/random.js diff --git a/src/Illuminate/Foundation/Events/DiscoverEvents.php b/src/Illuminate/Foundation/Events/DiscoverEvents.php index 497a8afa0912..6d52f65620f2 100644 --- a/src/Illuminate/Foundation/Events/DiscoverEvents.php +++ b/src/Illuminate/Foundation/Events/DiscoverEvents.php @@ -5,6 +5,7 @@ use SplFileInfo; use ReflectionClass; use ReflectionMethod; +use ReflectionException; use Illuminate\Support\Str; use Symfony\Component\Finder\Finder; @@ -38,9 +39,13 @@ protected static function getListenerEvents($listeners, $basePath) $listenerEvents = []; foreach ($listeners as $listener) { - $listener = new ReflectionClass( - static::classFromFile($listener, $basePath) - ); + try { + $listener = new ReflectionClass( + static::classFromFile($listener, $basePath) + ); + } catch (ReflectionException $e) { + continue; + } if (! $listener->isInstantiable()) { continue; diff --git a/tests/Integration/Foundation/Fixtures/EventDiscovery/Listeners/random.js b/tests/Integration/Foundation/Fixtures/EventDiscovery/Listeners/random.js new file mode 100644 index 000000000000..e69de29bb2d1