-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Dispatch an event when proxy initialization fails #1336
Dispatch an event when proxy initialization fails #1336
Conversation
* Disable the throwing of an exception | ||
* | ||
* This method indicates to the proxy initializer that the missing document | ||
* has been handled and no exception should be thrown. This can't be reset. |
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.
Why this can't be reset?
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.
The idea was that once a missing proxy has been handled (e.g. the object has been properly initialized) there shouldn't be the need for a different event subscriber to re-enable that exception.
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 think it'd be better to have stopPropagation
for that instead of combining two things (and our events are not supporting it anyway as of now :D )
eaa7fe5
to
a241bbd
Compare
* @param object $proxy | ||
* @param string $identifier | ||
*/ | ||
public function __construct($proxy, $identifier) |
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.
How about exposing corresponding DocumentManager
? It'd make event more powerful
To be honest, I'm not sure about the whole "prevent this exception from being thrown" thing. It was an idea that popped in my head last night and I thought I'd go with it. In theory, it makes sense but I think in practice there will be issues with that:
|
a241bbd
to
404e655
Compare
After additional discussion we decided to completely open up the |
404e655
to
04f4555
Compare
Dispatch an event when proxy initialization fails
@alcaeus Do you have an example of implementation ? |
The documentation specifies how you can disable the exception: http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/events.html#documentnotfound. Replacing the proxy object with |
With the exception disabled, what happens if i call for example $this->getImage(). |
Let's say you loaded a document Only when calling any other method or accessing a public property of It's important to note that at the time of initialization, we can't reset the invalid proxy instance. The proxy object might be used by multiple documents (think of multiple users holding a reference to the image), and since the proxy object itself is responsible for initializing itself, we can't change anything about the proxy object because you can't overwrite the value of If you want to control what happens with an invalid reference, initialize it in a controlled way while you still know the owning object and catch the |
It is, very detailed answer. Thanks a lot |
Supersedes #532, Closes #1258.
This builds on top of the code added in #532. The new
DocumentNotFoundEventArgs
class contains the proxy object and its identifier. Event subscribers can choose to handle the missing document and calldisableException()
on the $eventArgs object to prevent theDocumentNotFound
exception from being thrown.As mentioned in the ticket, this event is not available as a lifecycle callback because we don't have a valid object on which to call a lifecycle callback.