Conversation
(cherry picked from commit aa29dee)
As is, this is not a backport, as it contains changes from the accepted PR introducing the new API. |
|
Part of the point of namespaces is that the fully qualified class name provides the full meaning. Not every short class name must duplicate the preceding namespace segment, it's really only heavily used in places where the short name on its own could cause confusion because it can be duplicated across namespaces (i.e. does "Articles" refer to a table, model, controller). If you're going to insist on renaming the class though, I purposefully did not migrate the core helpers in Therefore, the core helpers MUST NOT be migrated to use the service registry until 5.0 when all of the existing method registration/overloading logic is removed. Extension helpers may safely migrate to the service registry. |
Here I don't agree. This would lead to a hard BC break, so why not offering that functionality right now in 3 already in a BC way? I think it is easier to move the condition up in the code afterwards for 5 than namespacing all the classes. |
|
You cannot migrate the core libraries to being service driven without an internal B/C break, no matter how you try to restructure
By flipping the ordering of 2 and 3 around, you get into a scenario where JHtml can potentially resolve a helper class that was built for the service oriented approach and would therefore be unusable with the existing logic. The current logic mandates static helper functions. Using The intent with the service registry is to be able to make JHtml helpers that are non-static, not just move the classes to another spot in the filesystem. See my refactoring of the install app's helper class as an example. The registry will continue to support static method resolution and use, but that really isn't the preferred use of the API. Either way there will be a hard B/C break when 5.0 comes around because of the deprecated API removal. That part cannot be mitigated without keeping the existing API in place, in which case I would just retract the service registry and keep the existing methodology and approach to JHtml in place forever. |
|
I understand your approach, but for the 3 series it is absolutely valid to introduce the registry and support already services. So it is legitime to do that in a BC way. In 4 we will be able to have the registry approach first and break BC in a minor way (if we want) and then removing it in 5. It is a much more hassle less way than just say with 5 we are going to remove it.
How can that happen, file lookups do only work for none namespaced files. This is the only way where automation is in place and thats only for the none namespaced code. Perhaps I do miss here something, can you give me an example how this situation can happen. |
|
Either a class is autoloaded (no path lookup) or a path lookup class gets resolved that is service designed, if for whatever reason that gets resolved it can and probably will result in errors. You might argue that it is more a developer error than something we need to care about, but if we're merging code to core knowing full well there is an easy code path that can result in generating errors we're doing something majorly wrong. /**
* This is the component.php file in our component's HTML helpers directory
*/
class JHtmlComponent
{
public function thing(): string
{
return $this->doThing();
}
private function doThing(): string
{
return 'the thing';
}
}
// This adds the class to the path lookups but the file isn't included yet
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
// This part will immediately fatal out if you don't have the class loaded by now, but let's say for the sake of argument it is loaded, and since JHtml internally prefixes classes by default as JHtml...
JHtml::getServiceRegistry()->register('component', new JHtmlComponent);
// Now try to use our component helper
JHtml::_('component.thing');With this PR as applied, the class will be resolved through the path lookups first and therefore attempt to use the class statically, uses of Because the use of the service registry changes the load order for things and potentially the internals of the helper class, the core libraries cannot be safely migrated except for with a major version bump because there is a high risk of B/C breakage. The service registry logic can be adapted into the HTML helper loader because it is new logic and 100% opt-in therefore cannot break anything with its introduction just by providing the API. Anyone migrating to it should at least document the change if they consider extension of JHtml helpers as part of their public API (and considering it's part of the JHtml design spec they probably should) and acting at a conservative level it would probably warrant a major version bump. If we want to migrate all of core to service driven for 4.0, then fine. I think we can conservatively wait for 5.0 to do it, but you and I have butted heads since day one about how quickly code is shifted to new methodology and old methodology deprecated and removed. But it absolutely cannot happen in a non-major release for the core libraries. Migrating |
|
To all respect but this is a situation you describe is very unlikely to happen as it can only happen when somebody uses the new feature. It will be detected 100% during development of the component when somebody traps into that mistake. Instead of making a hard BC break on version 5, I suggest to make here a step by step transition. But to move on and not argue this pr down, I suggest that I will revert the jquery service. In version 4 we can then again think about to ns the core services. |
|
You are not going to avoid a B/C break no matter how this code is implemented. The only way to not have a B/C break is to not remove the code I deprecated, to which point I would just revert my PR adding the registry and we be done with this. No matter how you try to spin my code under the false pretense of a backport, there are two pending B/C breaks:
@wilsonge make a call on this because I'm done here. |
|
I did not remove the code from you, and I reverted the JQuery service. So whats still wrong with it now? |
|
The two loading strategies are not compatible and you are attempting to force compatibility on it which actually causes the API to be more unpredictable. A A If you are overloading a If you are overloading a The long and short of this is that in absolutely no way can the two loading strategies be made compatible because the service registry offers features that are not available through the path lookup logic. By making it possible for service registry classes to be overloaded by the path lookup logic, you remove the benefits of the service registry and override the fact that a developer opted for a B/C breaking API change by explicitly migrating from the path lookup method to service registry. This MUST be a B/C breaking migration simply because it will force services to require overloading in an alternate manner if you want to provide any form of assurance that the classes can be used as expected. |
|
So I also reverted the registry code. Now it is a simple namespace change this pr. |
* 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
This is a backport of pr #17328 to Joomla 3. AdditionallyJHtmlgot namespaced and for demonstration purposesJHtmlJquery. If this one gets accepted, then I will namespace the rest of the services as well in another pr.Namespaces
JHtml, why not the registry, se comments below.Testing Instructions
Expected result
All is working as expected.
Actual result
All is working as expected.