laravel / telescope

An elegant debug assistant for the Laravel framework.
https://laravel.com/docs/telescope
MIT License
4.87k stars 582 forks source link

EventWatcher throws error when project is run through google drive when determining if string has the '@' symbol. #1517

Open lucas-quinn-guru opened 1 month ago

lucas-quinn-guru commented 1 month ago

Telescope Version

5.2.2

Laravel Version

11.22.0

PHP Version

8.2

Database Driver & Version

PostgreSQL 15.1 on aarch64-apple-darwin22.1.0, compiled by Apple clang version 12.0.5 (clang-1205.0.22.9), 64-bit

Description

Google Drives stores directory structure under a users email address which catches an error during a class_implements() check since code is using the @ as a delimiter and string check.

I was able to fix this locally, but not sure it it's correct by adding GoogleDrive as an option to reject().

    protected function formatListeners($eventName)
    {
        return collect(app('events')->getListeners($eventName))
            ->map(function ($listener) {
                $listener = (new ReflectionFunction($listener))
                        ->getStaticVariables()['listener'];

                if (is_string($listener)) {
                    return Str::contains($listener, '@') ? $listener : $listener.'@handle';
                } elseif (is_array($listener) && is_string($listener[0])) {
                    return $listener[0].'@'.$listener[1];
                } elseif (is_array($listener) && is_object($listener[0])) {
                    return get_class($listener[0]).'@'.$listener[1];
                } elseif (is_object($listener) && is_callable($listener) && ! $listener instanceof Closure) {
                    return get_class($listener).'@__invoke';
                }

                return $this->formatClosureListener($listener);
            })->reject(function ($listener) {
                if( Str::contains($listener, 'Laravel\\Telescope') || Str::contains($listener, 'GoogleDrive') ) {
                    return true;
                }
                return false;
            })->map(function ($listener) {
                if (Str::contains($listener, '@') ) {
                    $queued = in_array(ShouldQueue::class, class_implements(Str::beforeLast($listener, '@')));
                }

                return [
                    'name' => $listener,
                    'queued' => $queued ?? false,
                ];
            })->values()->toArray();
    }

Steps To Reproduce

run any project with telescope and filamentphp installed stored and run from GoogleDrive.

github-actions[bot] commented 1 month ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!