Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Deprecate application loading in JFactory::getApplication() #1729

Merged
merged 1 commit into from Mar 16, 2013
Merged

Deprecate application loading in JFactory::getApplication() #1729

merged 1 commit into from Mar 16, 2013

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Dec 1, 2012

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.

@elinw
Copy link
Contributor

elinw commented Dec 2, 2012

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.',
Copy link
Contributor

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..

Copy link
Contributor Author

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.

@eddieajau
Copy link
Contributor

I'd probably go further and suggest JFactory as a whole is not something we need in the core platform anymore.

@mbabker
Copy link
Contributor Author

mbabker commented Dec 3, 2012

You could make that argument. Once you have a JApplicationWeb instance (since that most directly replaces JApplication for that purpose), you can get the config, session, document, user (identity) and language objects out of the box. Adding support for the other objects if your application needs it is too easy. It's a matter of working away from using the factory methods I guess, and not having everyone's necks on the chopping block when the decision to deprecate it is made.

@eddieajau
Copy link
Contributor

I'm just suggesting it's not needed in the core platform anymore. I would probably argue against dropping it from the CMS.

@mbabker
Copy link
Contributor Author

mbabker commented Dec 3, 2012

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.

@eddieajau
Copy link
Contributor

Right, it's definitely a bigger job.

@davidhurley
Copy link

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.

@LouisLandry
Copy link
Contributor

This is great stuff @mbabker. I agree that JFactory is something that we need to think about. Going forward I want to see us using the application object for getting most of the things we used to get from JFactory and inject the application object into places where it is needed as a dependency. That will allow us a lot more flexibility and testability down the road.

@mbabker
Copy link
Contributor Author

mbabker commented Dec 17, 2012

ping

Is this something we want to slip in to 12.3 or hold off for a while longer?

eddieajau added a commit that referenced this pull request Mar 16, 2013
Deprecate application loading in JFactory::getApplication()
@eddieajau eddieajau merged commit 3b4d0d2 into joomla:staging Mar 16, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants