[4.0] Create a service registry for JHtml#17328
[4.0] Create a service registry for JHtml#17328wilsonge merged 1 commit intojoomla:4.0-devfrom mbabker:html-service-registry
Conversation
|
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. |
|
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 |
(cherry picked from commit aa29dee)
* Create a service registry for JHtml (joomla#17328) (cherry picked from commit aa29dee) * Namespace JHtml * PHP 5.3 compat * Do path lookup first and then check the registry * Renamed to ServiceRegistry * Revert jquery * Adapt classmap * Revert all the registry code * Revert all the registry code * Proper upper case
Summary of Changes
The manner in which services are integrated into JHtml are very sporadic and not the friendliest thing. The
registerandunregisterAPI 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
JHtmlclass 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
JHtmlhelper is updated to demonstrate this new methodology.Testing Instructions
Register a custom service to the registry by calling
JHtml::getServiceRegistry()->register($key, $handler);where$keyis the service key and$handleris either a PHP class name or a class object. Once registered, calls toJHtml::_($key . '.method');should use your service.Documentation Changes Required
The deprecation and new manner of working should be documented.