Event System API Reference
About 231 wordsLess than 1 minute
eventsapi-referencefilterable
Static Methods
Filterable::on(string $event, callable $callback): void
Register a global event listener for all filterable instances.
Parameters:
$event: The event name (e.g.,'filterable.applied')$callback: The callback to execute when the event fires
Example:
Filterable::on('filterable.applied', function (Filterable $filterable) {
logger("Filter applied");
});Filterable::observe(string $filterClass, callable $callback): void
Register an observer for a specific filter class.
Parameters:
$filterClass: The fully qualified filter class name$callback: The observer callback receiving($event, $filterable)
Example:
Filterable::observe(PostFilter::class, function ($event, Filterable $filterable) {
if ($event === 'applied') {
// Handle the event
}
});Filterable::flushListeners(): void
Remove all registered event listeners and observers.
Example:
Filterable::flushListeners();Filterable::getListeners(string $event): array
Get all registered listeners for a specific event.
Parameters:
$event: The event name
Returns: Array of callable listeners
Example:
$listeners = Filterable::getListeners('filterable.applied');Filterable::getObservers(string $filterClass): array
Get all registered observers for a specific filter class.
Parameters:
$filterClass: The filter class name
Returns: Array of callable observers
Example:
$observers = Filterable::getObservers(PostFilter::class);Instance Methods
enableEvents(): static
Enable events for this specific filterable instance.
Example:
$filter = PostFilter::create()->enableEvents();disableEvents(): static
Disable events for this specific filterable instance.
Example:
$filter = PostFilter::create()->disableEvents();