-
-
Notifications
You must be signed in to change notification settings - Fork 33
Add Events #428
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
base: master
Are you sure you want to change the base?
Add Events #428
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #428 +/- ##
============================================
- Coverage 89.16% 86.94% -2.23%
- Complexity 572 666 +94
============================================
Files 18 40 +22
Lines 1385 1616 +231
============================================
+ Hits 1235 1405 +170
- Misses 150 211 +61 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new event-dispatching system to ActiveRecord via attributes, letting models attach handlers for common events such as insert, update, and populate.
- Introduces
EventDispatcher
,EventInterface
, various event classes (e.g.BeforeInsert
,AfterUpdate
), and handler interfaces/abstract classes - Adds handler attributes (
DefaultValueOnInsert
,DefaultValue
,SetDateTimeOnUpdate
,DefaultDateTimeOnInsert
) to set default values or timestamps - Updates
composer.json
to requireyiisoft/event-dispatcher
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/Event/EventDispatcher.php | Implements event discovery via attributes and listener registration |
src/Event/Handler/HandlerInterface.php | Defines the interface for attribute-based event handlers |
src/Event/Handler/AbstractHandler.php | Base class managing property names and default event list |
src/Event/Handler/DefaultValueOnInsert.php | Handler that sets default values on BeforeInsert |
src/Event/Handler/DefaultValue.php | Handler that sets default values on AfterPopulate |
src/Event/Handler/DefaultDateTimeOnInsert.php | Inserts timestamps on BeforeInsert |
src/Event/Handler/SetDateTimeOnUpdate.php | Updates timestamps on BeforeUpdate |
src/Event/*.php | New event classes covering save, insert, update, delete, populate |
composer.json | Adds yiisoft/event-dispatcher to requirements and suggestions |
Comments suppressed due to low confidence (2)
src/Event/Handler/HandlerInterface.php:20
- [nitpick] Consider adding a PHPDoc comment for the
handle
method to explain what kinds of events it processes and any expectations about modification of the event or model.
public function handle(EventInterface $event): void;
src/Event/Handler/SetDateTimeOnUpdate.php:1
- No unit tests were added for
SetDateTimeOnUpdate
; please add tests to verify default timestamp generation and custom property name handling.
<?php
# Conflicts: # tests/ActiveRecordTest.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this implementation. Let's add docs for it and missing tests. Awesome job. Waiting forward to use it.
How does it affect performance btw.?
A good test for it and also a handy functionality could be
|
Please no manipulations in the constructor |
…dListenersFromAttributes()`
# Conflicts: # src/AbstractActiveRecord.php # src/ActiveQuery.php
# Conflicts: # src/AbstractActiveRecord.php # src/ActiveRecordInterface.php # src/Trait/FactoryTrait.php
# Conflicts: # tests/ActiveQueryTest.php # tests/Driver/Oracle/ActiveQueryTest.php
Looks 👍 overall. Need docs. |
Uh oh!
There was an error while loading. Please reload this page.