Use this page when you need the exact public methods behind actions, filters, and collectors. It explains how to register, inspect, order, and remove callbacks, with signatures and return values in one place.
The published signatures and edge cases here match magdicom/hooksv2.0.0-beta.2. Start with the guide for your hook type, then use this page when you need a complete method summary.
public function addCollector(
string $hookPoint,
array|callable $callback,
int $priority = 10,
): RegistrationHandle
Use it when:
you need to register one independent contribution.
Applies to: Collectors
Returns: A RegistrationHandle.
Configuration: Yes; the callback remains until removed.
All three accept a hook name, a PHP callable or callable array, and an optional priority. The default priority is 10; lower numbers run first, and equal priorities keep registration order. The callback is invoked only when the matching dispatch method runs.
Registrations belong to the Hooks instance that created them. The default priority is 10. Lower numbers run first, and equal priorities retain registration order.
you need to verify exact object ownership before removing or sharing a handle.
Applies to: Registration handles
Returns: true only for the Hooks instance that created the handle.
The handle is a reference to a registration, not a copy of the callback. Keep it when a temporary extension needs to remove exactly the listener it added.
remove() is registration-id based. It removes the exact registration and returns true; calling it after that registration has already been removed returns false:
This matters when you register equivalent or duplicate callbacks. A handle belongs to the particular Hooks object that returned it. belongsTo($hooks) checks that exact ownership rather than comparing configuration.
Use the inspection methods when you need to decide whether an extension point is populated, count registrations, or examine the handles that were returned by registration. They do not invoke callbacks.
public function collectors(string $hookPoint): array
Use it when:
you need only the collector registrations at a point.
Applies to: Collectors
Returns: Collector handles in dispatch order.
For hasAction(), hasFilter(), and hasCollector(), omit the callback when you only need to know whether that type has any registration. Pass the callback when callback identity and priority matter. The default priority is 10; the priority argument is relevant to callback matching.
The arrays contain handles, not callback return values. They are snapshots of the registrations at the time you call the inspection method. Use RegistrationHandle::remove() when you want to remove the exact registration represented by one of those handles; use the callback-based removal methods when you intentionally want to match by callback and priority.
public function removeCollector(
string $hookPoint,
array|callable $callback,
int $priority = 10,
): bool
Use it when:
you want callback-based removal of one collector at a specific priority.
Applies to: Collectors
Returns: true when the first matching registration is removed; otherwise false.
Configuration: Yes; it changes the registry.
These methods remove the first matching callback of the requested type and priority. They do not accept a RegistrationHandle; call the handle’s remove() method for exact registration-id removal. A callback registered as an action is not removed by removeFilter().
Bulk methods remove registrations and return the number removed:
Each method returns the number of registrations it removed. A hook point limits the operation; omitting it is a registry-wide operation for the selected type.
Hooks sorts listeners by ascending priority and then by registration id. Equal-priority callbacks therefore run in a predictable order.
Before dispatch, Hooks creates a sorted listener snapshot. Adding or removing registrations while a callback runs does not alter the list selected for that invocation. The change appears on a later invocation:
<?php
declare(strict_types=1);
use Magdicom\Hooks;
$hooks=newHooks();
$late=staticfunction():void {
// Added during dispatch, so it does not run in that same snapshot.
$hooks->doAction('order.cancelled'); // The new listener is available here.
Nested collect(), process(), and render() calls use their own snapshots. Exceptions reach the caller, and a later invocation can still use the registry.
For value transformation and raw result behavior, see the hook type pages. Processor, renderer, resolver, and callback behavior is covered in the advanced core reference.
They apply respectively to actions, filters, and collectors. A callback may be a callable, object method array, or class-name method array; invalid callback resolution or callback exceptions surface when the callback is prepared or invoked.
setProcessor() and setRenderer() share one collector endpoint slot. collect() always bypasses that slot. See processors and renderers for built-in behavior.
public function renderWith(
string $hookPoint,
Renderer|callable|string $renderer,
mixed ...$arguments,
): string
Use it when:
you need a one-off rendering strategy.
Applies to: Collectors
Returns: The supplied renderer's string output.
With no listeners: The renderer receives an empty array.
Exceptions: InvalidRendererException for invalid configuration or non-string output.
Configuration: No; the supplied renderer is used for this call only.
processWith() and renderWith() are one-off alternatives when the caller wants to choose the processing or rendering strategy at invocation time. They collect the endpoint once and leave any persistent slot untouched. See one-off processing and one-off rendering for examples.
These methods do not change action, filter, or collector behavior. The debug callback and source label are metadata, not a replacement for explicit arguments or application logging.
The ProcessingContext constructor stores the original invocation arguments as a list. RegistrationHandle exposes the lifecycle methods above. NativeResolver::resolve(string $className): object creates a class with new $className(); the Laravel wrapper replaces this with container-backed resolution.
RegistrationHandle::__construct(...) is public in the released class but is an implementation-created value: normal callers should obtain handles from addAction(), addFilter(), or addCollector() rather than constructing one. Its internal remover closure preserves exact registration-id behavior.