User tests: Successful: Unsuccessful:
With this pr an extension can provide an autoload.php file which allows to set up its classpaths and classloaders (eg. composer) before the application gets executed. Like that there is no need anymore during runtime to manually mess with classloading in extensions. This means an extension must not write anymore require
, include
or JLoader::import()
. All is set up already when the application is executed.
Additionally an extension can define alias when some classes got moved around to keep backwards compatibility. The same procedure as we do with the core classes.
This pr is an optimized version of the original intention of the pr #15226. The extension can define a new attribute autoload
in it's manifest file which tells the core the location of an autoloader file, similar to the installer script file.
It reuses the obsolete namespace column as the autoloader spec.
A new query is executed on every page load. But with this approach we can remove all the class name registrations and class loading which every extension has to deal with. So when all do have adapted on that set up, we will speed things up as every JLoader::import, etc. can be removed.
Open the categories manager in the back end of com_content.
The sidebar is shown.
The sidebar is shown.
Autoload support needs to be documented.
Status | New | ⇒ | Pending |
Category | ⇒ | SQL Administration com_admin com_categories com_content Installation Libraries |
@franz-wohlkoenig - The patch tester doesn't apply any SQL updates. Go to PhpMyAdmin (or whatever database manager you're using), and execute the following:
ALTER TABLE `#__extensions` ADD autoload tinyint(3) DEFAULT 0 AFTER state;
Labels |
Added:
?
|
Category | SQL Administration com_admin com_categories com_content Installation Libraries | ⇒ | SQL Administration com_admin Postgresql com_categories com_content Installation Libraries |
@franz-wohlkoenig currently autoloader and namespace pr's on Joomla 4 are changing stuff on the core and do alter the db schema. So you need to run the update queries which do come with the pr's.
Honestly we are in development mode, so it is IMO not required to test them like on staging. Mostly feedback by the community and a test by the Joomla 4 release leader are enough to get it merged.
So its better not test and wait on Dev. for go to Test.
Yes, think so.
Category | SQL Administration com_admin com_categories com_content Installation Libraries Postgresql | ⇒ | SQL Administration com_admin Postgresql com_categories com_content Installation Libraries Unit Tests |
Labels |
Added:
?
|
Honestly we are in development mode, so it is IMO not required to test them like on staging. Mostly feedback by the community and a test by the Joomla 4 release leader are enough to get it merged.
Honestly, I think that's a bad idea in general. If it can be tested, it should be properly tested. Otherwise we will introduce way to many bugs.
Honestly, I think that's a bad idea in general.
I was referring to the autoload and namespace pr's not all pr's in general. For sure stuff needs to be tested.
I have tested this item
@laoneo - Oops by bad. Did that and now working fine.
Title |
|
Title |
|
Some thoughts:
I wonder how much sense it makes to load the autoload.php files of every extension
This set up here is especially useful for extensions which do use composer and none standard namespaces. So honestly I don't know how to create here some magic for lazy loading. But I don't think so that this is an issue problem at all as registering a classloader is not too time consuming.
Eg it's not possible to have a single autoload.php shipped in a library package
It can easily be extended for libraries if needed.
So honestly I don't know how to create here some magic for lazy loading. But I don't think so that this is an issue problem at all as registering a classloader is not too time consuming.
It may be not very time consuming, but in most cases the query and the registering is just useless as the classes will not be used at all. That's why I ask if we really need some magic for those cases where extensions have non-joomla-standard namespaces. It's simple enough to register / include an own classloader in those extensions.
It's simple enough to register / include an own classloader in those extensions.
That's what this pr is about. Like that the extension developer is able to load it's own extension classes the way she/he needs.
I meant they can add as well a single line into their initial extension file(s) to load their classloader (when needed). Without Joomla having to query the database and loading several unneeded classloaders.
I'm just not convinced we need that "magic" here.
This isn't just about magic behaviors or loading extra data into the autoloader. Part of the aim with class autoloading is you don't have to be explicitly aware of the filesystem structure, make sure the class is loaded, load it if need be, then use it; you just use the resources. Extensions are littered with manual loading declarations of class dependencies, not just within the active component but modules and plugins too. The number of places calling jimport()
or JLoader::register()
needs to go down massively.
Sure, I got that part. My concern isn't about autoloading in general (which is obviously fine). It's about doing an extra database query and loading all autoloaders on each pageload, regardless if the classes of that extension are even used or not. Depending on the site that may be a lot of classloaders to always include.
I don't see the issue when a component or module (or whatever) has to add a single line of code to load their own classloader. But if you think it's worth to add a query and always load all autoloaders to remove that line then I'm fine.
I can't say if it's worth or not.
It's about doing an extra database query
Its a simple query with an index. So not much loss here. The gain for all the import and require calls is bigger IMO (of course just a guess).
I don't see the issue when a component or module (or whatever) has to add a single line of code
You have to add that line on multiple classes, because they can be called without the full context where they are used. So you end up in a normal request with multiple import calls.
The gain for all the import and require calls is bigger IMO (of course just a guess).
I'd question exactly that. Because the import and requires for specific classes can be removed from extensions anyway when they use an autoloader. That's independant from this PR.
We're only talking about a call to register/load the autoloader for a given extension. In your proposal all of them would be loaded in addition to an additional query. In most cases you only would need a few of them.
You have to add that line on multiple classes, because they can be called without the full context where they are used. So you end up in a normal request with multiple import calls.
Yep, it would be in one single class/file per extension, namely the initial "bootstrapping" one (for components the dispatcher one). Modules and plugins only would need it if they actually use a class from their respective component or have an own namespaced class structure. Imho that's not a big deal to do.
Or I still miss something obvious.
Because the import and requires for specific classes can be removed from extensions anyway when they use an autoloader
I'm talking here about classes which are used outside of the ordinary extension context. Like fields, helpers, layouts all code code which is used outside of an ordinary loaded extension. Or extensions like plugins who do want to load libraries from a component, etc.
Imho that's not a big deal to do.
When we start doing proper PSR-4 namespacing, then we should simplify it that way, that during execution process, an extension developer shouldn't care about autoloading. At least what I think should be the case in a proper system.
I'm talking here about classes which are used outside of the ordinary extension context. Like fields, helpers, layouts all code code which is used outside of an ordinary loaded extension.
Ah ok, this makes sense, yes.
I still don't think it's a good idea to load all autoloaders prematurely but at the moment don't see another way then.
At least I tried
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-05-14 05:53:37 |
Closed_By | ⇒ | laoneo |
After install PR using Patchtester got: