Skip to content

CP-17501 datamapper events - #17506

Merged
niden merged 8 commits into
5.0.xfrom
CP-17501-datamapper-events
Aug 18, 2026
Merged

CP-17501 datamapper events#17506
niden merged 8 commits into
5.0.xfrom
CP-17501-datamapper-events

Conversation

@niden

@niden niden commented Aug 18, 2026

Copy link
Copy Markdown
Member

Hello!

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Added lifecycle events to the DataMapper connections, fired through Phalcon\Events\Manager and named on the new Phalcon\DataMapper\Pdo\Events class: dm:beforeConnect/dm:afterConnect, dm:beforeDisconnect/dm:afterDisconnect, dm:beforePerform/dm:afterPerform, dm:beforeExec/dm:afterExec, dm:beforeQuery/dm:afterQuery, dm:beforeBeginTransaction/dm:afterBeginTransaction, dm:beforeCommit/dm:afterCommit, dm:beforeRollBack/dm:afterRollBack and dm:connectionLost. prepare() has no events of its own because perform() calls it, which would report one operation twice. The connect, disconnect and connectionLost events report a change of the connection state and fire whichever method causes it, so an automatic reconnect reports the lost connection and the new one. Phalcon\DataMapper\Pdo\Connection\Decorated does not fire the connect and disconnect events because it never connects and cannot disconnect.

Added getEventsManager() and setEventsManager() to Phalcon\DataMapper\Pdo\Connection\AbstractConnection, and therefore to Phalcon\DataMapper\Pdo\Connection and Phalcon\DataMapper\Pdo\Connection\Decorated, and to Phalcon\DataMapper\Pdo\ConnectionLocator, which gives its events manager to every connection it returns, including the ones it builds on demand. The two classes now carry the Phalcon\Contracts\Events\EventsAware contract. Phalcon\DataMapper\Pdo\Connection\ConnectionInterface is unchanged, so classes that implement it directly keep working

Added Phalcon\DataMapper\Pdo\Exception\OperationCancelled, thrown when a listener cancels one of the before* events. The operation does not run. To cancel, a listener must call $event->stop() and also return false: stop() alone returns the value of the listener, which the connection cannot tell apart from "no listeners", and false alone is replaced by any later listener that returns a value while the events manager is not in stopOnFalse mode. The after* events are not cancellable

Thanks

niden added 7 commits August 18, 2026 12:13
This reverts commit 7e35277ee1cde48b249afb368e5a26b8a3b90f9b.
This reverts commit f1f0eb95ded53dc035f7502d10a341408f9ea0f8.
Assisted-by: Claude Code
@niden
niden requested a review from Jeckerson August 18, 2026 19:56
@niden niden self-assigned this Aug 18, 2026
@niden niden added new feature request Planned Feature or New Feature Request 5.0 The issues we want to solve in the 5.0 release labels Aug 18, 2026
Assisted-by: Claude Code
@niden
niden merged commit fd6fc91 into 5.0.x Aug 18, 2026
299 of 303 checks passed
@niden
niden deleted the CP-17501-datamapper-events branch August 18, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.0 The issues we want to solve in the 5.0 release new feature request Planned Feature or New Feature Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant