-
Notifications
You must be signed in to change notification settings - Fork 1
Validate events #17
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
Validate events #17
Conversation
|
Why immutable? |
|
Most of the CMS Plugins are immutable except tables (also suggested in the documentation) and there is no reason to modify the event beside the allowed arguments. |
|
@HLeithner you know I will not like it 😉 I think it a bit to much. I would validate only "entry" level, not that deep. Additionally, in current case the event work like a "hook", it should be allowed to modify url and files, other way whole events does not make any sense. joomla-cms/libraries/src/Event/AbstractEvent.php Lines 27 to 34 in 3a5984d
About "imutable", it only means you cannot add/remove event arguments (with I would reset all changes back to |
|
Even more. After reading that comment again, I think we made mistake. For Url the |
|
The reason is why I validate the file object is because the file object has not a proper interfaces and class defined that should validate the input. I don't know why doesn't have it's own interface maybe creating one is a better idea but I would expect that could and in a b/c... which is not covered by our b/c policy because it's not in the library... hmm... Any way we as the cms have to see anything that comes from a plugin as possible broken and must validate it. If we don't do it in the plugin we have to do it in the model. Which is the wrong position because each plugin which is called needs a proper state and if one plugin fucks it up it should instantly trigger an error. The complete concept about the plugin system (using setArgument that calls setXYZ function) is to make a proper validation. And the validation I implemented is very weak. Of course it doesn't matter if you call it |
|
Okay then. Only a couple notes :) I understood what do you mean, but it not a place to do full object validation. We have to live with it, because bc. Hmhm, I see that (And maybe we have to merge File and Files event to single, and use only Files, they basically the same. But can stay as is) In general it is okay. |
|
actually it's not a b/c because we have a documentation for the basic values it's defined in the AdapterInterface
yes that sounds ok only the subject/eventname should differ? So you have a chance to detect which actually triggers it. Maybe different eventnames (file and files) with the same object, in both cases we use subject as array of files? |
For this purpose then 2 event is good, maybe can extend one from another, to share validation method. |
|
The name of the event is set in the constructor which sounds a bit useless when we always have one object per event right? So changing
should fit right? edit: and of course the following getArgument line... here could be a problem if more then one file is returned... |
|
yea, kind of it
|
|
Well, then maybe better leave as is |
|
For me this is the wrong place to add such deep validation for the state where Joomla is now. This must be for now in the model, similar to what we do with forms when saving data. If you really want to do this, then you need to do it properly, otherwise it looks like a half baked solution when it is implemented in one event that way and in another in a different way. Make it for Joomla 4.1 or 4.2, but then properly across the whole code base. The same what we did with the namespacing of MVC. First we changed com_content and afterwards, when we agreed, then we changed the other extensions. I suggest to do this, otherwise we are going to introduce a new direction in a pr for a minor release, where no developer will figure out what the heck we did here. |
|
Sadly the new event system documentation (or plans) aren't really good, at least I didn't found much. But what I know is that it was introduced 2013 so I think it's not new only wrongly implemented for the new events, because it's really much work to do things right... I wouldn't like to introduce more "half-bake" events. The alternative is to create the interface, class and a trait for the file validation and integrate it the model and the plugin, so it validates if someone sets new values to the new file class. then the plugin only needs to validate all the checks I did for the properties. |
|
There are multiple ways how to validate the data. An alternative to the interface/class/trait approach would be that the provider manager always returns a wrapper adapter which contains internally the original adapter from the plugin. All function calls are then delegated to the internal adapter and the return value will be validated by the adaptermanager where the wrapper has a reference to. This adapter is also available in the model, so validation can be done then after the events again. I see it that way, that the model is responsible to deliver data correctly to the controller. Honestly a plugin hasn't to deliver the data perfect as IMO the plugins can be rather dumb. Internally we need to make sure that the data is delivered properly to the front end. And last but not least, an extension developer has not the intention to deliver incorrect data, as the system would crash then immediately. From my experience it is even the opposite, you have to harden the plugins more than core does as you have to deal with any kind of situation, especially in the plugin system where you have to deal with all kinds of plugins, states, versions and requests. |
That the point of "in event validation", it should crash and burn immediately. Not waiting when event call ends and then crash , because then it hard to determine which plugin make an error. That is a main issue of all systems which provide hooks.
Sure, the developer has not such intention. However, it can happen accidentally (or because lack of knowledge), and be hidden until certain conditions happens. |
|
Just to be clear here. I'm not against validation. But not in a pr here in a fork of the CMS where developers have to dig deep to find the reason why we did it that way. |
|
Ok, to move here forward. @Fedik are you ok with the changes from @HLeithner ? If yes I will merge it and then we can go ahead with the one in upstream. |
|
yes, I think it is good for what we have |
* Add some events when fetching media data * Use dispatcher to trigger event * Use an event instance * Class per event (#15) * Argument validations and getter (#16) * Class per event * Argument validations * global * Use result from events * Copy year * Use internal variable * void * adapt model * Validate events (#17) * Revert commit ec8b4c8 ccd02cb and 9a2a119 * Validate and immutable events * Update administrator/components/com_media/src/Event/FetchMediaFileEvent.php Co-authored-by: Harald Leithner <[email protected]> * Update administrator/components/com_media/src/Event/FetchMediaFilesEvent.php Co-authored-by: Harald Leithner <[email protected]> * Rename the events * Cleanup events Co-authored-by: Fedir Zinchuk <[email protected]> Co-authored-by: Harald Leithner <[email protected]>
Validate input and make the events immutable