Skip to content
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

Public API's GenericEvent replacement #17650

Closed
wants to merge 6 commits into from

Conversation

blizzz
Copy link
Member

@blizzz blizzz commented Oct 22, 2019

In some (but not every) place we use Symfony's GenericEvent class. It depends on their deprecated Event. We have made the switch to use the new Event already. In itself it is not contradicting (unless code checks for old or new Event class).

In order to complete the transition, I added a new GenericEvent in the OCP space, which extends the new Event class, but is also compatible signature-wise to Symfony's GenericEvent.

Thus, adjusting is easy by replacing the namespace. And yet it is a hard break. Going full to new GenericEvent means that any code or app that listens to the one of the events and type-hints the old GenericEvent, will run into an error condition. Since we need to deal with classes, not interfaces, there is no way around this sadly.

Thus, if we accept this change, we need to touch any other app that is also outside of this repository and communicate as critical change. I do not like doing it, but it is a good opportunity to go for a baseline of our events and gain some consistency.

Thoughts?

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
*/
public function offsetGet($offset) {
if ($this->hasArgument($offset)) {
unset($this->arguments[$offset]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unset($this->arguments[$offset]);
return $this->arguments[$offset];

*
* @since 18.0.0
*/
public function setArguments(array $args = []): GenericEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows integer keys, while setArgument doesnt
I think we should unify this?

* @link https://php.net/manual/en/arrayaccess.offsetset.php
* @since 18.0.0
*/
public function offsetSet($offset, $value): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this explodes when offset is not a string, which you enforce on setArgument but this method here allows.

@ChristophWurst
Copy link
Member

If many of the changes are breaking, wouldn't it make sense to migrate to Event directly if the GenericEvent features aren't used?

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above

@ChristophWurst
Copy link
Member

https://github.com/search?q=org%3Anextcloud+%22GenericEvent%22&type=Code for the code we might have to touch 😢

@blizzz blizzz added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Oct 23, 2019
@blizzz
Copy link
Member Author

blizzz commented Oct 23, 2019

If many of the changes are breaking, wouldn't it make sense to migrate to Event directly if the GenericEvent features aren't used?

Could do… it makes the constructor case messier. It is not terrible though. However it would be cumbersone to tell whether the thrown events make use of the available features of the GenericEvent or not. I'd prefer to keep it separated.

https://github.com/search?q=org%3Anextcloud+%22GenericEvent%22&type=Code for the code we might have to touch cry

About half of it is addressed with this PR already. Then there is of course a number of potential apps not on github. Rest assured I am uneasy with this as well and still carry a portion of doubts.

The question is, how can we do a smooth transition? Since a lot of code directly relies on Symfony's GenericEvent, we cannot simply put an interface on top or phase it out.

What we could do differently however is to sent the events twice, with the new and the old implementation. And then we are able to remove the old GenericEvent at a later point, 3 years from 18 or what. The SymfonyAdapter already logs deprecation messages, when the old event type is being used. Sadly, we cannot do it when listeners are addressed, unless patching Symfony's event dispatcher… not sure this is a good idea. All in all that's probably the better thing.
Update To avoid crashes, it will need new event names, this will duplicate a lot more :-/ /Update

@blizzz
Copy link
Member Author

blizzz commented Nov 6, 2019

closing in favor of #17834

@blizzz blizzz closed this Nov 6, 2019
@MichaIng MichaIng deleted the enh/noid/generic-event-replacement branch June 8, 2021 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants