Repository navigation
Releases
Releases · Pollora/hook
v2.0.3
Fixed
- Registering an invokable object (
Action::add('init', new Handler)) without an argument count threw aTypeError, and a static method written as a string ('Handler::run') threwCallbackAnalysisFailedException: the parameters were counted withReflectionFunction, which reads neither. They are now read from the object's__invoke()and from the named static method. - An asynchronous handler whose descriptor names a private or protected method was retried as many times as
triesallowed, each attempt failing the same way withThe handler of … is not callable. Resolving the descriptor now fails at once with anUnresolvableHandlerthat says the method is not public.
v2.0.2
Fixed
- A closure registered after another closure was freed no longer inherits that closure's argument count. The count was cached under the closure's object ID, which PHP hands to the next closure once the first is freed, so WordPress could be told to pass a callback too few arguments (an
ArgumentCountError) or too many. The count is now held by the closure itself and goes with it.
Changed
AbstractHookthrows named exceptions from the newPollora\Hook\Domain\Exceptionsnamespace instead of a bare\RuntimeException:HookMethodNotFoundException(a class registered without a method has no method named after the hook),CallbackResolutionFailedException(the class of a callback cannot be built; it wraps the cause, with its code) andCallbackAnalysisFailedException(reflection cannot read the callable). Their messages say how to fix the problem. They extendHookException, which extends\RuntimeException, so acatch (\RuntimeException)keeps working and the existing message prefixes (Failed to resolve '…',Method '…' not found in class '…',Failed to analyze callable:) are unchanged- The daily recovery task is registered through
Recovery::run(), which returns nothing as an action callback must;Recovery::recover()still returns the number of executions scheduled again
Internal
- The WordPress suite (
composer test:integration, still available ascomposer test:wordpress) also covers theActionandFilterfacades against WordPress's own hook tables, and no longer definesDISABLE_WP_CRONa second time when the installedwp-config.phpalready does - The
Architecturetest suite runstests/Arch.php, which the default run left out - PHPStan runs with
szepeviktor/phpstan-wordpress(WordPress stubs and rules), at level 5; the ignores it makes unnecessary are removed and unmatched ignores are reported again - The WordPress test fixtures use
wp_doing_cron()instead of theDOING_CRONconstant - The
unserialize()of a queued closure carries anosemgrepjustification: the payload's HMAC, keyed fromwp_salt(), is checked before it is read
v2.0.1
v2.0.0
[2.0.0] - 2026-10-13
Asynchronous actions queue through the drivers of pollora/schedule. Work queued by 1.x runs unchanged; the only break is the two removed driver classes below.
Changed
- WP-Cron and Action Scheduler are the drivers of
pollora/schedule, which the package now requires:Async\Drivers\ScheduledDriverqueues through them and keeps what is the hook's own, the message an event carries and where the payload lives. Nothing changes for what is already queued: the hook, the Action Scheduler groups (polloraor the queue name), the identifier-only WP-Cron events and thepollora_async_options are the same, so work queued by 1.x runs once 2.0 is installed.->async(),#[Async],Async::fake(),via()and their options do not change Async::listen()keepspollora/async/runandpollora/async/recoveron WP-Cron (thepollora/schedule/protected_hooksfilter), whatever driver the site gave pollora/schedule:via('wp-cron')still means WP-Cron- An Action Scheduler action of the hook lives in its own group and is never in the
cronindex of pollora/schedule
Removed
Async\Drivers\WpCronDriverandAsync\Drivers\ActionSchedulerDriver, with no alias. Code that used them directly (the framework does not) usesScheduledDriver::wpCron()andScheduledDriver::actionScheduler(), or the drivers of pollora/scheduleWpCronDriver::handles()andclaim(): usePayloadStore. The recovery task (recover(),scheduleRecovery(),RECOVERY_HOOK,RECOVERY_GRACE) moved toAsync\Recovery
v1.5.0
Added
AbstractHook::all()lists every registration made through a hook instance, keyed by hook name, for debugging tools that mark Pollora's callbacks- The
pollora/async/dispatchedaction announces each queued handler with its payload and delay
Full Changelog: v1.4.1...v1.5.0
v1.4.1
Fixed
- The runner checks that
determine_locale()exists before restoring the locale, not onlyswitch_to_locale(), so an environment that defines one without the other (a test suite, an early bootstrap) no longer fails with an undefined function.
Full Changelog: v1.4.0...v1.4.1
v1.4.0
Added
Async::setDefaults(): the attempts, backoff andasUserevery asynchronous registration starts from. The framework sets them fromconfig/hooks.php.Async::injectParametersUsing(): handler parameters that are not hook arguments are injected at execution. By default, a parameter is injected when its type is a class or interface that does not travel as a hook argument (WordPress objects, enums, dates,JsonSerializableandAsyncContextdo). These parameters are not requested from WordPress, so they can sit anywhere in the signature. The framework resolves them from its container.Async::receive(..., throwOnFinalFailure: true): the last failure is announced throughpollora/async/failed, then thrown instead of reported, for a driver whose queue records failures itself (a Laravel job then lands infailed_jobs). Retries still happen while attempts are left.
Changed
- A handler parameter with no hook argument left takes its default value, so a later
AsyncContextor injected parameter still gets its own.
Full Changelog: v1.3.0...v1.4.0
v1.3.0
Changed
- The default driver is now
auto: Action Scheduler when a plugin bundling it is active and initialised, WP-Cron otherwise, resolved on each dispatch. A site with WooCommerce therefore queues through Action Scheduler after upgrading; payloads already queued through WP-Cron still run. SetPOLLORA_ASYNC_DRIVERtowp-cronto keep the previous behaviour. - The WP-Cron recovery task also leaves alone a stored payload whose Action Scheduler action is still pending.
- The type of
capture()andwhen()callbacks is documented ascallable, so closures with typed parameters pass static analysis.
Added
capture()on an asynchronous registration: a callback run at trigger time, in the original request, with the hook arguments; the array it returns is read back at execution throughAsyncContext::get(). Captured values travel like arguments. A handler class's publiccapture()method is used whencapture()is not called.when(): queue only when the callback, given the hook arguments, returnstrue. It runs before the capture, and an exception it throws goes through, as it would synchronously.tries(): a handler that throws is queued again, through the driver that queued it, until it has used its attempts; each failed attempt is reported, the last one is fired aspollora/async/failed.backoff()sets the seconds before each retry (default 10, 60, then 300; the last value repeats). A handler that no longer exists is not retried.asUser(): run as the user who fired the hook, then remove that user. Without it the handler runs without a current user.onQueue(): queue name, used as the Action Scheduler group and the Laravel queue; WP-Cron ignores it.unique(): merge identical triggers (same hook, same handler, same arguments) while the first one has not started running. The lock is an option that is not autoloaded, taken atomically withadd_option(), released when the first attempt starts, and expiring afterunique(for: …)seconds (one day by default) if never released; the daily maintenance task deletes expired locks. A lock that cannot be stored is a queuing failure, never a silent merge.action-schedulerdriver, offered when a plugin bundling Action Scheduler is active and its data store is initialised (never a dependency). The payload travels whole as the action argument, the queue name becomes the group (polloraby default), and history is visible in Tools › Scheduled Actions. A payload too long for Action Scheduler's arguments (8,000 characters as JSON) is kept in an option that is not autoloaded and the action carries only its identifier.Async::setAutoDrivers(): the driversautotries, in order.Async::fake()for tests: records queued handlers instead of queuing them, whatever the driver, withAsync::assertDispatched()(by class, descriptor orclosure, with an optional callback receiving the payload and the delay),assertDispatchedTimes(),assertNotDispatched()andassertNothingDispatched(). Arguments are still normalized, so one that cannot travel fails here too;runDispatched()runs the recorded handlers. Assertions go through PHPUnit when it is installed.- Closures as asynchronous handlers, when
laravel/serializable-closureis installed (suggested, not required). The closure is serialized with it and signed with an HMAC-SHA256 whose key derives fromwp_salt('auth'), or is set withAsync::useClosureKey(); the signature is checked before anything is unserialized, and an altered payload or a changed key fails with an explicit report. The closure is checked at registration but signed when its hook first fires, sincewp_salt()is pluggable and not loaded while plugins load. A closure made from a named function or method (strlen(...),$object->method(...)) travels by that name. - Payloads record the driver that queued them, the queue,
asUser, the backoff and the unique lock. These fields are optional, so payloads queued by 1.2.0 still run.
Full Changelog: v1.2.0...v1.3.0
v1.2.0
Added
- Asynchronous actions:
add(...)->async()replaces each callback of the lastadd()call by one that queues it, at the same priority. The handler runs later, with the hook arguments and, if it declares a parameter of that type, anAsyncContext(user, site, locale, hook, trigger date, attempt).- Options on the returned
PendingAsync:delay()(seconds orDateInterval),via()(driver),keepMissing(), andexcept()to keep some hooks synchronous;async(except: ...)too. A hook inexceptthat the registration does not have throws in debug mode and is reported otherwise. - The handler travels by name (
CallableDescriptor), its arguments in normalized form (ArgumentNormalizer: WordPress objects by reference, enums, dates,JsonSerializable; any other object rejected), all in a versioned JSONAsyncPayload. A closure or an anonymous class is rejected at registration. - At execution the site and locale of the original request are restored. A handler that fires its own hook does not queue itself again. A failure is reported and announced through the
pollora/async/failedaction, and never stops other queued handlers. - When queuing fails (an argument that cannot travel, an unavailable driver), debug mode (
WP_DEBUG, orAsync::setDebug()) throws; otherwise the incident is reported and the handler runs in place.
- Options on the returned
Asyncentry point:extend()to register a driver,driver(),reference()to carry more object kinds,reportUsing()to route incidents (PHP error log by default),setDebug(). The internal hookpollora/async/runis listened to as soon as an Action service exists.AsyncDriverandObjectReferencecontracts.wp-crondriver, the default: the payload is stored in an option of its own, not autoloaded (pollora_async_{id}), and the single event carries only its identifier, so the autoloadedcronoption stays small. The payload is deleted when its execution starts; an event that fires twice runs once. A daily task (pollora/async/recover, scheduled the first time the driver queues) schedules again the payloads whose event was lost, for example after thecronoption was reset, once they are an hour old; an unreadable stored payload is deleted. Each recovery is reported.syncdriver: runs the handler in the request, after the same JSON round trip.- Default driver, from the first of:
Async::setDefaultDriver(), thePOLLORA_ASYNC_DRIVERconstant, thepollora/hook/async_driverfilter,wp-cron.autoresolves towp-cronfor now.
Changed
- PHP 8.3 is now the minimum version.
- The
Actioncontract declaresasync(). A class of your own implementingPollora\Hook\Domain\Contract\Actionmust addpublic function async(string|array $except = []): PendingAsync. The adapters of the package already do. Pollora\Hook\Action::add()andPollora\Hook\Filter::add()return the adapter instead of nothing, soAction::add(...)->async()chains.remove()andexists()find an asynchronous handler by the callback it was registered with.
Fixed
- A
[ClassName::class, 'method']callback naming an instance method is now instantiated at registration, through the callback resolver when one is set, as a class name is. WordPress used to receive it as a static call and threw aTypeErrorwhen the hook fired. Static methods and classes not loaded yet are unchanged. remove()andexists()accept that same[ClassName::class, 'method']form and find the instance it was registered as.exists()now accepts a non-callable array or string as its callback.
Full Changelog: v1.1.1...v1.2.0