cakephp/cakephp — pull request #1462 by markstory (2013-07-30 02:35:06+00:00)
Title: 3.0 beforefind

Add beforeFind event to ORM\Table.

Keep things simple and add a very basic event for beforeFind. In the future the updated behaviors will be able to use this event.

I've decided to solve a long standing problem and make it super simple to replace the result of a find() entirely. Stopping the event and setting a return will circumvent the entire find and return the provided value. This makes it really easy to replace find actions with cache results for example. One outstanding issue to making this really easy to do is that find() currently returns an ORM\Query instance. If instead it always returned an ORM\ResultSet it would be much simpler to do cache bypasses on find operations. I'm considering changing the return of Table::find() for that reason. Perhaps with the addition of scoped finders that change will be easier to accept.