Deprecate application loading in JFactory::getApplication() #1729
Conversation
This makes a lot of sense to me. |
* Instead, an Exception will be thrown if the object is not set. | ||
*/ | ||
JLog::add( | ||
'Using JFactory::getApplication() to instantiate applications is deprecated. JApplicationBase classes should register directly to JFactory::$application.', |
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 believe this triggers a checkstyle line length warning
..
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 updated commit should fix that.
I'd probably go further and suggest |
You could make that argument. Once you have a |
I'm just suggesting it's not needed in the core platform anymore. I would probably argue against dropping it from the CMS. |
I don't disagree, I'm just saying it would take some work to break the Platform of its use, the most common probably being the getApplication and getDbo methods. |
Right, it's definitely a bigger job. |
I agree that JFactory may not be needed in the core but think it may be a bit before that is realized. I think this commit is a good fix to move towards using JApplicationBase as opposed to the legacy class. |
This is great stuff @mbabker. I agree that |
ping Is this something we want to slip in to 12.3 or hold off for a while longer? |
Deprecate application loading in JFactory::getApplication()
JFactory::getApplication() is heavily tied in to working with the legacy JApplication class, making it nearly impossible to properly refactor the method to work with the newer JApplicationBase classes. Since JFactory::getApplication() is heavily used to retrieve the application object, instead of deprecating and removing the method completely, instead I propose to deprecate its code to handle instantiating an application instance, in this case, JApplication. In 13.3 when JApplication is removed from the legacy tree, the method will be converted to throwing an Exception if the application object in JFactory is not set by applications. This allows this heavily used API to continue to be used to globally retrieve the application object.
As well, I've added a check to ensure that JApplication is present if getApplication() is actually loading an instance. Since it is in the legacy tree, there is the chance it is not present. An Exception is thrown in this instance.