joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Use CMSWebApplicationInterface in controllers

Open wilsonge opened this issue 4 years ago • 15 comments

Summary of Changes

Moves Joomla MVC Controllers over to use CMSWebApplicationInterface instead of CMSApplication. This may be of use in the future to console applications who wish to use the Controller system.

  • Changes type hints in constructors to CMSWebApplicationInterface
  • Changes some instances in controllers where we currently use \Joomla\CMS\Factory to use the app property (especially FormController)

~Note this is a draft PR because I need to figure out how to resolve the calls to getLogger in BaseController - as the FIG LoggerInterface is not contained in the CMSApplicationInterface as things stand.~

Testing Instructions

No changes expected in the web interface. Code review of changes.

Documentation Changes Required

None

wilsonge avatar Mar 29 '20 02:03 wilsonge

Removing beta blocker actually. Loosening the constraints can be done in any minor version

wilsonge avatar Mar 29 '20 03:03 wilsonge

Is it not a BC break when the signature of the constructor changes?

laoneo avatar Apr 01 '20 13:04 laoneo

No. As long as it's compatible with the old typehint (which it is - it's a higher level) it's totally b/c

wilsonge avatar Apr 01 '20 13:04 wilsonge

@mbabker thanks for the review. Do you have any opinion on the Logging part?

wilsonge avatar Apr 10 '20 23:04 wilsonge

@PhilETaylor can you cast a more experienced pair of eyes over this? I’ve done some more refactoring and still not totally sure about the approach here.

obviously need to change it to target 4.1 too but will sort that another day. Time for some 😴

wilsonge avatar Jan 04 '22 01:01 wilsonge

added to my list, but first, bedtime :) Thanks.

PhilETaylor avatar Jan 04 '22 01:01 PhilETaylor

This may be of use in the future to console applications who wish to use the Controller system.

I do not see the point that the Controllers and the whole MVC behind it can then be used, as a Console application can never implement getMenu.

laoneo avatar Jan 05 '22 08:01 laoneo

I do not see the point that the Controllers and the whole MVC behind it can then be used, as a Console application can never implement getMenu.

I'm not sure I really see your point here? My entire driver here is that we are going to have scenarios if console if a first class application where you might have controller tasks which are specifically for a console and shouldn't be exposed to a web application ever and obviously we need to take into account even on shared tasks there might not be an active menu item in those scenarios

wilsonge avatar Jan 05 '22 15:01 wilsonge

Ok, if you write controllers specifically for console app, then will work. What I did understand was, that all controllers (site/admin) will then work in console apps.

laoneo avatar Jan 05 '22 15:01 laoneo

So the controller has to be aware of the request format (because, for example, the input object is going to be different and likely will have different naming conventions) - your output format is also likely to be different (obviously you rarely want to redirect which is web application specific or display a html view inside the console). Obviously we need to minimise differences as much as practically possible - but there's always going to be some differences. The end goal should be where the state is injected into the Model so that the model eventually becomes largely unaware of application (it's a grand goal that's going to take a long time to reach).

wilsonge avatar Jan 05 '22 15:01 wilsonge

Totally agree

The end goal should be where the state is injected into the Model so that the model eventually becomes largely unaware of application (it's a grand goal that's going to take a long time to reach).

Something we should consider version 5.

laoneo avatar Jan 05 '22 15:01 laoneo

Can you fix the conflicts here and make it ready for review? Would like to bring this one forward.

laoneo avatar Apr 20 '22 13:04 laoneo

Can you fix the conflicts here and make it ready for review? Would like to bring this one forward.

laoneo avatar Jun 15 '22 14:06 laoneo

Done but needs a full test rework now to go with it because the mock application objects don’t return the logger even though the real one always will. Will work on it over next few days

wilsonge avatar Jun 18 '22 21:06 wilsonge

This pull requests has been automatically converted to the PSR-12 coding standard.

joomla-bot avatar Jun 27 '22 21:06 joomla-bot

I've changed the basebranch to 4.3-dev, since we wont be merging this into 4.2.

Hackwar avatar Oct 21 '22 08:10 Hackwar

Wouldn't it possible to introduce a more abstract class that accepts any application and leave BaseController as web-only? Or does something prevent that at this point (like legacy loader thing)? Otherwise, document the new exceptions.

SharkyKZ avatar Dec 13 '22 13:12 SharkyKZ

Wouldn't it possible to introduce a more abstract class that accepts any application and leave BaseController as web-only? Or does something prevent that at this point (like legacy loader thing)? Otherwise, document the new exceptions.

My aim was to do it a bit differently - most controllers only have a display controller so I wanted to move display into it's own subcontroller of base controller in a future major version (use an empty class in the current version for b/c)

Then that leaves the hold/release/check edit ids - they are common to all the child classes - so I was thinking of maybe putting them in a trait???? (less sure but they are all group'd together)

Finally there's redirect and checkToken which are basically both proxy methods. I'm not that fussed about just the exceptions for them given they are so small?

I mean with all the benefits of hindsight I should have made a BaseWebController or something. But it's still not that clear if it's a good idea for like 2-3 methods.

I'm pretty sure I want display controller to be it's own thing. Less sure about how to rework the others tho - happy to take ideas.

wilsonge avatar Dec 13 '22 16:12 wilsonge

This pull request has been automatically rebased to 5.0-dev. No new features will be merged into Joomla! 4.3 series. Joomla! 4.4 series is a bridge release to make migration from Joomla! 4 to 5 as smooth as possible.

HLeithner avatar May 08 '23 15:05 HLeithner

Thanks, can you please write a manual migration documentation?

HLeithner avatar Sep 03 '23 08:09 HLeithner