Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple listeners being attached to models #192

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Database/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function bootNicerEvents()
if ($model->methodExists($method)) {
// Register the method as a listener with default priority
// to allow for complete control over the execution order
$model->bindEvent('model.' . $method, [$model, $method]);
$model->bindEventOnce('model.' . $method, [$model, $method]);
}
// First listener that returns a non-null result will cancel the
// further propagation of the event; If that result is false, the
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Traits/SoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function bootSoftDelete()
if ($model->methodExists('beforeRestore')) {
// Register the method as a listener with default priority
// to allow for complete control over the execution order
$model->bindEvent('model.beforeRestore', [$model, 'beforeRestore']);
$model->bindEventOnce('model.beforeRestore', [$model, 'beforeRestore']);
}
/**
* @event model.beforeRestore
Expand All @@ -54,7 +54,7 @@ public static function bootSoftDelete()
if ($model->methodExists('afterRestore')) {
// Register the method as a listener with default priority
// to allow for complete control over the execution order
$model->bindEvent('model.afterRestore', [$model, 'afterRestore']);
$model->bindEventOnce('model.afterRestore', [$model, 'afterRestore']);
}
/**
* @event model.afterRestore
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function bootValidation()
if ($model->methodExists('beforeValidate')) {
// Register the method as a listener with default priority
// to allow for complete control over the execution order
$model->bindEvent('model.beforeValidate', [$model, 'beforeValidate']);
$model->bindEventOnce('model.beforeValidate', [$model, 'beforeValidate']);
}

/**
Expand All @@ -87,7 +87,7 @@ public static function bootValidation()
if ($model->methodExists('afterValidate')) {
// Register the method as a listener with default priority
// to allow for complete control over the execution order
$model->bindEvent('model.afterValidate', [$model, 'afterValidate']);
$model->bindEventOnce('model.afterValidate', [$model, 'afterValidate']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Halcyon/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function bootNicerEvents()
if ($model->methodExists($method)) {
// Register the method as a listener with default priority
// to allow for complete control over the execution order
$model->bindEvent('model.' . $method, [$model, $method]);
$model->bindEventOnce('model.' . $method, [$model, $method]);
}
// First listener that returns a non-null result will cancel the
// further propagation of the event; If that result is false, the
Expand Down