RecipeApplyRequested
Fires when a recipe should be applied to the current installation. A mutable event for program configuration import.
WordPress plugin
Last updated: October 26, 2026
RecipeApplyRequested fires when a recipe should be applied to the current installation. Recipes are fully resolved JSON configurations that describe programs, program groups, distributors, collaborator groups, collaborators, currencies, autofulfillers, mappings, and tracking and commerce settings. This event is the mechanism that turns a recipe payload into actual records in the database, and it is mutable: handlers record what they create so the caller can report the results.
The event ID is recipe_apply_requested, and its fully qualified class is Siren\Recipes\Core\Events\RecipeApplyRequested.
What does this event carry?
The event carries a RecipePayload model, which contains the deserialized recipe data. Read it with getPayload().
use Siren\Recipes\Core\Events\RecipeApplyRequested;
public function handle(Event $event): void
{
if (!$event instanceof RecipeApplyRequested) {
return;
}
// Each broadcast targets one section. Act only on yours.
if (!$event->isInBatch('programs')) {
return;
}
$payload = $event->getPayload();
foreach ($payload->getPrograms() as $key => $programData) {
// Create the program described under this recipe key.
}
}
Does the event arrive in batches?
Yes. Every apply runs as a series of broadcasts, one for each section of the recipe, and each one names its section. The sections go in this order: currencies, autofulfillers, programs, programGroups, distributors, collaboratorGroups, tracking, and commerce, then collaborators, collaboratorGroupMembers, mappings, and a last finalize broadcast. Call isInBatch() with the section your handler writes and return early when it answers false. Without that check, your handler runs on every broadcast and creates its records many times over.
Collaborators and mappings are also split into pages. sliceForBatch() returns the items for this broadcast, and getBatchOffset() and getBatchLimit() give the window. isInBatch() answers true for every section only when code dispatches the event itself without a context, as Siren’s scenario generator does.
Why is this event mutable?
Unlike most events in Siren, RecipeApplyRequested is designed for handlers to write back to it. As each handler processes its portion of the recipe, it records what it created under the recipe’s own key, using the event’s mutation methods. After all handlers have run, the caller can inspect the event to see exactly what was created, enabling confirmation messages and error reporting.
public function handle(Event $event): void
{
// After creating a program from the recipe payload...
$event->addCreatedProgram($key, $program);
// After creating a program group...
$event->addCreatedProgramGroup($key, $programGroup);
// After creating a distributor...
$event->addCreatedDistributor($key, $distributor);
// A collaborator group is recorded by its ID and name.
$event->addCreatedCollaboratorGroup($key, $groupId, $groupName);
}
The other add methods follow the same shape: addCreatedCollaborator(string $key, Collaborator $collaborator), addCreatedCurrency(string $key, CustomCurrency $currency), and addCreatedAutofulfiller(string $key, Autofulfiller $autofulfiller).
A later stanza often needs a record an earlier one made, such as a program group that points at its programs. Look those up by recipe key with getProgramIdForKey(), getProgramGroupIdForKey(), getDistributorIdForKey(), getCollaboratorGroupIdForKey(), and getCollaboratorIdForKey(). Each returns the database ID, or null when nothing was created for that key.
This pattern keeps recipe application decoupled. Each domain handles its own portion of the recipe independently, and the event itself serves as the coordination point that tracks the aggregate result.
For the full lifecycle of system events and how they connect to the rest of Siren’s architecture, see the System Events overview.