HasInsertSignals
Provides insertion-related signals.
This trait defines signals that are emitted before and after a document is inserted, allowing observers (slots) to react to these events.
Signals:
$beforeInsert: Emitted before the insertion occurs.$afterInsert: Emitted after the insertion is complete.
Example usage:
$document->initializeInsertSignals();
$document->beforeInsert?->connect(fn($doc) => echo "About to insert {$doc->id}");
$document->afterInsert?->connect(fn($doc) => echo "Inserted document {$doc->id}");
Tags
Table of Contents
Properties
- $afterInsert : Signal|null
- Signal emitted after a document has been inserted.
- $beforeInsert : Signal|null
- Signal emitted before a document is inserted.
Methods
- initializeInsertSignals() : static
- Initializes the insertion-related signals.
- releaseInsertSignals() : static
- Release the insertion-related signals.
Properties
$afterInsert
Signal emitted after a document has been inserted.
public
Signal|null
$afterInsert
= null
Observers connected to this signal receive the inserted document as a parameter.
$beforeInsert
Signal emitted before a document is inserted.
public
Signal|null
$beforeInsert
= null
Observers connected to this signal receive the document that is about to be inserted.
Methods
initializeInsertSignals()
Initializes the insertion-related signals.
public
initializeInsertSignals() : static
Creates new Signal instances for $beforeInsert and $afterInsert.
Tags
Return values
static —Returns $this for method chaining.
releaseInsertSignals()
Release the insertion-related signals.
public
releaseInsertSignals() : static
Nullify and disconnect the afterInsert and beforeInsert signals.
Return values
static —Returns $this for method chaining.