Skip to content

Comments

[4.0] Create a service registry for JHtml#17328

Merged
wilsonge merged 1 commit intojoomla:4.0-devfrom
mbabker:html-service-registry
Aug 18, 2017
Merged

[4.0] Create a service registry for JHtml#17328
wilsonge merged 1 commit intojoomla:4.0-devfrom
mbabker:html-service-registry

Conversation

@mbabker
Copy link
Contributor

@mbabker mbabker commented Jul 28, 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.

@laoneo
Copy link
Member

laoneo commented Aug 7, 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.

@mbabker
Copy link
Contributor Author

mbabker commented Aug 7, 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.

@wilsonge wilsonge merged commit aa29dee into joomla:4.0-dev Aug 18, 2017
@zero-24 zero-24 added this to the Joomla 4.0 milestone Aug 18, 2017
laoneo pushed a commit to Digital-Peak/joomla-cms that referenced this pull request Aug 22, 2017
@laoneo laoneo mentioned this pull request Aug 22, 2017
laoneo added a commit to Digital-Peak/joomla-cms that referenced this pull request Aug 29, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants