#97264ext_localconf.php architecture with namespaces
Description
I noticed from TYPO3 v11 there is an updated best-practice architecture for handling with ext_localconf.php. I’m referring to this document:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/ConfigurationFiles/Index.html
Mentioning NOT to use global namespaces to avoid namespace nesting. This is correct, but I think it would be a better approach to use classified namespaces for the extension vendor/extension key:
like this:
<?php
namespace My\FooBarExt {
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3_MODE') || die('Access denied.');
(function ($extKey) {
// ... here is what usually is inside ext_localconf.php
})('my_foobar_ext');
}
I would much more favor to replace ext_localconf.php with a Package-Registration File/Class that looks like those one used in Symfony or Laravel Packages being able to configure f.e. Site YAML (site-package config & extension routes) and services provided by the package.
This would follow more the new approach to go with Symfony/HTTP-Foundation coding standards. Here’s an example for a ServiceProvider from laravel which I really like for how it is handling package (aka extension) registration:
https://laravelpackage.com/03-service-providers.html#creating-a-service-provider
Please drop me some constructive feedback. Please let me know if there are plausible reasons NOT to use any php namespace wrapping in ext_localconf.php or is this only meant for the global “namespace {}” without classified name?
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 5
-
Gabriel Kaufmann TYPOworx GmbH | NewMedia commented 03/31/22, 09:02
-
Stefan Bürk changed tracker
EpicFeature 04/10/22, 03:20 -
Simon Schaufelberger changed description 04/30/22, 13:44
-
Simon Schaufelberger commented 04/30/22, 13:45
@Gabriel: This issue tracker doesn’t support markdown, please use the “pre” tag for it. See toolbar how to make syntax highlighting.
AFAIK the goal is to get rid of ext_* files completely in the long run and configure everything with symfony services. See https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-96733-NewBackendModuleRegistrationAPI.html in which direction it goes.
-
Georg Ringer commented and changed status
NewClosed 03/31/25, 18:07Hey Gabriel,
thanks for creating the issue! As stated by Simon, the core evolves and uses configuration files, e.g.
Configuration/Backend/Modules.phporConfiguration/Icons.phpand theext_localconf.phpfiles are getting smaller and smaller.As stated in the linked docs (could have been changed since creation of the issue), you can use the
usekeyword
> Having a namespace allows extension authors to import classes by the keyword use.There are no concrete plans what is moved as next but as this is rather a very general issue and the namespaces can be imported, I am closing the issue. Feel free to contact me on slack if you got some questions
Just noticed another docu targeting TYPO3 v11.4 which also targets the namespace handling:
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.4/Important-94280-MoveContentsOfExtPhpIntoLocalScopes.html
Example code from the cache file:
```
namespace {
// Content of EXT:frontend/ext_localconf.php
}
```
Will this namespace be wrapped automatically by core around the ext_localconf.php code so that any namespace in ext_localconf.php will be wrapped inside (therefore nested)?
I still favor for the possibility to use classified namespaces and may be handle those ext_localconf.php with their own package-namespace (either by automatically if unset or manual from ext_localconf.php if given).
Glad to hear feedback to this.