? Success

User tests: Successful: Unsuccessful:

avatar mbabker
mbabker
28 Jul 2017

Summary of Changes

The manner in which services are integrated into JHtml are very sporadic and not the friendliest thing. The register and unregister API maps specific keys to single callbacks and integrating services from components requires registering filesystem paths to scan for specific files. We can do better than this.

This PR does two things.

First, it introduces a new service registry. The registry allows developers to register a service key to either a PHP class name (static method calls, essentially what the system does now) or a class object (removing the requirement to either manually register callbacks through JHtml::register() or to use purely static methods).

Second, this PR deprecates the existing logic for registering things. Manual lookup paths, registering (and unregistering) callbacks, and support for a three-piece key will be removed with Joomla 5.0 if this is accepted in favor of registering everything to the service registry. The three-piece key is what allows developers to replace the JHtml class prefix with a prefix of their choosing, with this registry it really won't matter what they name their classes as the key will no longer have to directly map to a class name. Path lookups are being removed as by the time we get to 5.0 extension architecture should really be at a point where it won't be needed.

The installation application's JHtml helper is updated to demonstrate this new methodology.

Testing Instructions

Register a custom service to the registry by calling JHtml::getServiceRegistry()->register($key, $handler); where $key is the service key and $handler is either a PHP class name or a class object. Once registered, calls to JHtml::_($key . '.method'); should use your service.

Documentation Changes Required

The deprecation and new manner of working should be documented.

avatar joomla-cms-bot joomla-cms-bot - change - 28 Jul 2017
Category Installation Libraries
avatar mbabker mbabker - open - 28 Jul 2017
avatar mbabker mbabker - change - 28 Jul 2017
Status New Pending
avatar laoneo
laoneo - comment - 7 Aug 2017

Perhaps it would be a good idea also convert com_content to use the registry to see how extension devs have then to register the services in their components in a centralized way. Beside that it looks ok.

avatar mbabker
mbabker - comment - 7 Aug 2017

I haven't touched components since you all started introducing the dispatcher stuff, but theoretically this would be something done for "legacy" components in the front controller file (i.e. content.php) before executing the controller or in a dispatcher at a point where component services are being registered (which if I'm not mistaken we still don't actually have a "proper" mechanism for).

The frontend JHtmlIcon class can't be registered in this way right now. That same class name is used in multiple components. The backend JHtmlContentAdministrator class could, but again we lack an actual process for a component to register services right now.

avatar wilsonge wilsonge - change - 18 Aug 2017
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-08-18 15:39:16
Closed_By wilsonge
Labels Added: ?
avatar wilsonge wilsonge - close - 18 Aug 2017
avatar wilsonge wilsonge - merge - 18 Aug 2017

Add a Comment

Login with GitHub to post a comment