? Feature PR-4.4-dev Pending

User tests: Successful: Unsuccessful:

avatar Fedik
Fedik
12 Sep 2023

Summary of Changes

As now every set/getArgument in Event have a check for set<Name>/get<Name> callback, for value pre-processing.
However this naming is confusing and misleading, because these methods does not set anything, but used for the value validation or transformation.

I suggest to rename this to onSet<Name>/onGet<Name>
The code have a falback for old naming, untill Joomla 6.

If this will be acepted, it need to update all new events in 5.0-dev branch.

Testing Instructions

All should work as before

Link to documentations

Please select:

  • Documentation link for docs.joomla.org: IDK
  • No documentation changes for docs.joomla.org needed
  • Pull Request link for manual.joomla.org: joomla/Manual#195
  • No documentation changes for manual.joomla.org needed
avatar joomla-cms-bot joomla-cms-bot - change - 12 Sep 2023
Category Libraries
avatar Fedik Fedik - open - 12 Sep 2023
avatar Fedik Fedik - change - 12 Sep 2023
Status New Pending
avatar Fedik Fedik - change - 13 Sep 2023
Labels Added: ? Feature PR-4.4-dev
avatar wilsonge
wilsonge - comment - 13 Sep 2023

I don't see this as worth the b/c break. Good docs is better to explain clearly what it means

avatar Fedik
Fedik - comment - 13 Sep 2023

I don't see this as worth the b/c break.

It do not break old code.
The backward compatibility here we can extend untill Joomla 7 or 10 or anything.

avatar wilsonge
wilsonge - comment - 13 Sep 2023

At some point people have to migrate. And it's these naming convention changes that annoy developers more than anything else.

avatar Fedik
Fedik - comment - 13 Sep 2023

Yeah, I hate it too ?
This is also an argument to make it now, or never.

Because currently in j4 ~40 event classes,
And upcomming 5.0 will have ~170 event classes. And after it will be released there will be no easy way to change it.

Not like I very want to work on it, but I found many people confused by these naming very much. Especialy when trying to do a public setFoobar(...) {$this->setArgument('foobar', ...)}, and wonder why they get infinity loop.

avatar HLeithner
HLeithner - comment - 20 Sep 2023

I'm in favor for this change, only question for b/c, what happen if someone extends a core event (what not should be done) and override an existing setXXX method, this would be in the new version converted to onSetXXX() but the override will no longer work right?

avatar Fedik
Fedik - comment - 20 Sep 2023

For existing (in 4.x), we just do "proxy" call, example this

protected function setSubject($value)

will be:

// add @deprecation tag
protected function setSubject($value){
  //... old code 
}

protected function onSetSubject($value) {
  return $this->setSubject($value);
}

There around 40 of such methods.

And all new events in 5.0, we just have to edit to use new onSetFoobar.

avatar Fedik
Fedik - comment - 20 Sep 2023

I have prepared PR for all new event classes in 5.0 #41830

avatar Fedik Fedik - change - 20 Sep 2023
The description was changed
avatar Fedik Fedik - edited - 20 Sep 2023
avatar laoneo
laoneo - comment - 20 Sep 2023

What about having a generic function prepare($key, $value) function instead of all these duplicated code. onGet/Set sounds for me like the good old PHP 4 days.

avatar laoneo
laoneo - comment - 20 Sep 2023

Or if a generic one is not ok, then like prepareFoo().

avatar Fedik
Fedik - comment - 20 Sep 2023

And here is the update for existing 4.x events #41831

avatar Fedik
Fedik - comment - 20 Sep 2023

What about having a generic function prepare($key, $value)

With this you need to have a switch case or if else.
And in the result much more complex code I think.
But in general also can work.

Or if a generic one is not ok, then like prepareFoo().

Naming can be any. To me onSet/onGet is fine.

avatar laoneo
laoneo - comment - 20 Sep 2023

I would change the naming to something more meaningfull as onSet says nothing what the function actually does. But I leave here the decision to @HLeithner, as you guys did the heavy work on the events conversion in 5. If you think it is ok, fee free to merge.

avatar HLeithner
HLeithner - comment - 20 Sep 2023

After a longer discussion on mattermost, we didn't find a better name and it fits the "event" naming a bit, so I merge this for 4.4 and we will change the names as described by @Fedik in #41831

avatar HLeithner HLeithner - close - 20 Sep 2023
avatar HLeithner HLeithner - merge - 20 Sep 2023
avatar HLeithner HLeithner - change - 20 Sep 2023
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2023-09-20 15:19:12
Closed_By HLeithner

Add a Comment

Login with GitHub to post a comment