Issue Details (XML | Word | Printable)

Key: DC-280
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Jonathan H. Wage
Reporter: Adam Jensen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Doctrine 1

Add pre/postHydrateResultSet() events

Created: 23/Nov/09 11:38 PM   Updated: 08/Jun/10 04:09 PM
Component/s: Connection, Query, Record
Affects Version/s: None
Fix Version/s: None


 Description  « Hide
Over the last several weeks I've been working on streamlining the access control logic in the application I'm working on, and I realized that Doctrine's event listeners might be able to help. For more detailed background information take a look at http://groups.google.com:80/group/dallasphp/browse_thread/thread/91e3f107cd611adf ...but here's the problem in a nutshell:

Since my application's access control logic is all implemented in PHP rather than in the database (i.e., I can't add access control to my queries as a simple WHERE clause), I'm looking for a way to hook into the query process just after the records have been hydrated and actually modify the result set that gets returned, such that only permissible records show up in the final result set.

Unfortunately, although there are several listener methods that look promising for this, none of them seem to have access to the data being returned. For instance, if I run a custom query via Doctrine_Query::execute(), the postQuery() hook definitely runs ...but it doesn't give me access to anything but the query string itself.

Since, in some instances (e.g., hydration listeners), the Doctrine_Event object is assigned arbitrary data that the listener can modify, I'm wondering if the same thing couldn't be done more universally?



 All   Comments   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Jonathan H. Wage added a comment - 24/Nov/09 12:01 AM
In Doctrine 1.2 you can create custom hydrators. You can extend the core hydrators to remove the data you want? I think that would work.

Adam Jensen added a comment - 24/Nov/09 07:45 PM
Sure enough, that does the trick!

There are a couple of downsides, though, that might be worth considering in terms of future development:

1. It would be nice to be able to specify constructor arguments for the hydrator, so that collaborators can be injected. In my example, the hydrator needs access to the application's access control list object; currently it's simply retrieving it from a global registry, but it would be nice for testing's sake to be able to inject it instead.
2. It would also be nice to be able to chain multiple hydrators together; that's one reason I was looking at listeners, since they've got that capability already. That approach allows you to keep distinct behavior distinct a lot more easily.

Ultimately, I'd still kind of like to see another listener method available ...say, preHydrateResultSet() and postHydrateResultSet()? I think that would be a more flexible approach, even though the custom hydrator solution works quite well.

Thanks!
Adam


Jonathan H. Wage added a comment - 24/Nov/09 07:49 PM
I like the idea. I'll move this to 1.3. I don't think we're gonna have a 1.3 version but if we do, it'll be there.

Jonathan H. Wage added a comment - 15/Mar/10 02:22 PM
We can include this in a 1.2.x release if you would like to provide a patch and some tests. Thanks, Jon