- How does Eventy differ from Laravel’s native events system?
- Eventy mimics WordPress’s actions/filters, offering a more flexible hook system for modifying data or executing callbacks at specific points. Laravel’s native events are event-driven (fire-and-forget), while Eventy’s filters return modified values, making it ideal for CMS-like or plugin architectures where data transformation is key.
- Can I use Eventy alongside Laravel’s built-in events?
- Yes, but avoid naming collisions. Eventy integrates with Laravel’s service container, so you can use both systems. For example, prefix hooks with a namespace like `app.user.created` instead of `user.created` to prevent conflicts with Laravel’s events or other packages.
- What Laravel versions does Eventy support?
- Eventy is designed for Laravel 10+ and requires PHP 8.1+. Older versions (e.g., Laravel 9) may work with minor adjustments, but the package assumes modern PHP features like strict types and attributes. Check the GitHub repo for version-specific branches if needed.
- How do I register actions/filters dynamically (e.g., from plugins)?
- Use the `Eventy::action()` or `Eventy::filter()` methods to register hooks dynamically. For plugins, bind hooks in a service provider’s `boot()` method or use middleware to scope hooks to specific routes. Example: `Eventy::action('plugin.register', fn() => $this->handlePlugin());`
- Are there performance concerns with heavy hook usage?
- Yes, actions/filters introduce runtime overhead due to callback execution. Profile critical paths with tools like Blackfire or Xdebug. Limit hooks in hot paths (e.g., API routes) and avoid deep filter chains. Eventy supports priority-based execution to optimize order.
- How do I test Eventy hooks in PHPUnit?
- Mock hooks by stubbing the `Eventy` facade or using Laravel’s `Events::fake()` for native events. For complex filter chains, create test doubles that return predictable values. Example: `Eventy::shouldReceive('filter')->andReturn('modified_value');`
- Can Eventy replace Laravel’s observers or macros?
- No, but it complements them. Use observers for event-driven workflows (e.g., sending emails on model creation) and Eventy for dynamic behavior modification (e.g., altering query results or UI components). Macros are better for class-level extensions, while Eventy excels in plugin-like extensibility.
- How do I handle hook conflicts in a multi-package environment?
- Use namespaced hook names (e.g., `package_name.hook`) and register hooks in isolated service providers. For shared hooks, document them in a central package and enforce naming conventions. Eventy’s priority system lets you control execution order if multiple packages hook into the same event.
- Does Eventy support conditional hook registration (e.g., middleware-based)?
- Yes, you can conditionally register hooks using middleware or service container bindings. For example, bind a hook in a middleware’s `handle()` method or use Laravel’s `when()` method to conditionally register callbacks. Example: `Eventy::filter('theme.render', fn() => $this->modifyForAdmin())->when(fn() => auth()->check());`
- What’s the upgrade path if Eventy breaks changes in future versions?
- Check the changelog for deprecations and use abstracted layers (e.g., facades or services) to minimize coupling. Eventy aims for backward compatibility, but breaking changes may require hook name adjustments or callback refactoring. Test upgrades in a staging environment before production deployment.