Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuditingEventServiceProvider disables Laravel's Event Auto-Discovery #923

Closed
ManuelLeiner opened this issue Apr 22, 2024 · 2 comments
Closed
Labels
bug Issue, error or unexpected behavior

Comments

@ManuelLeiner
Copy link

ManuelLeiner commented Apr 22, 2024

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 11.4.0
Package version 13.6.5
PHP version 8.3.6

Actual Behaviour

I've already filed an extensive bug report in the laravel/framework repository, which has been rejected. I am not yet 100% convinced that this not at least partly a framework problem.

Once the auditing package is installed, Laravel's event auto-discovery no longer works. This means that events and listeners from my application will not be detected. I (want to) rely on auto-discovery.

I am pretty sure this is caused by the AuditingEventServiceProvider inheriting from the framework's base EventServiceProvider.

I have found that the framework's EventServiceProvider is no longer registered once another service provider inheriting from that base class is registered. This is the case for your service provider. I am still trying to figure out how the framework works and registers those service providers.

As the auditing service provider is registered instead the framework's service provider, this check in shouldDiscoverEvents will return false.

Expected Behaviour

Using your package, Laravel's EventServiceProvider is still registered and event auto-discovery works as expected.

Steps to Reproduce

  1. Fresh installation: https://laravel.com/docs/11.x/installation#sail-on-macos
  2. Follow setup
  3. ./vendor/bin/sail art make:event TestEvent
  4. ./vendor/bin/sail art make:listener TestListener
  5. Type hint the event (3) in the listener (4)
  6. ./vendor/bin/sail art event:list
  7. ./vendor/bin/sail composer require owen-it/laravel-auditing
  8. ./vendor/bin/sail art event:list
  9. ./vendor/bin/sail composer remove owen-it/laravel-auditing
  10. ./vendor/bin/sail art event:list

Check the output of (8) and (10) and you will see that at (8) the event and listener are discovered while at (10) they no longer are.

Please have a look at the code in the original bug report.

Possible Solutions

If this package would rely on Manual Registering Events, i.e. not inheriting and not using the $listen array anymore, but instead using the facade in any of the boot functions, I think the problem could be solved.

On the other hand, I still think this is a bug in the framework.

@parallels999
Copy link

@ManuelLeiner
Copy link
Author

Omg sorry .. this one time I do not check for open PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue, error or unexpected behavior
Projects
None yet
Development

No branches or pull requests

2 participants