Repository navigation
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