Provide option to load autoloadable controllers for extras
Feature request
Summary
Provide option to load autoloadable controllers for extras.
I would like to be able to load controllers from paths such as: /core/components/extra/src/Controllers/Admin.php
Why is it needed?
Since MODX 3, the core uses autoloadable controllers, it like to have this option for extra's as well.
Suggested solution(s)
The getControllerClassName method in the modManagerResponse class needs to be extended for this.
Something like this would be possible, but I was wondering if there is a more elegant approach for this?
$namespace = array_key_exists($this->namespace, $this->namespaces) ? $this->namespaces[$this->namespace] : $this->namespaces['core'];
if (is_dir($namespace['path'] . 'src/')) {
$controllerFiles = glob($namespace['path'] . 'src{/,/*/,/**/}Controllers/' . $action . '.php', GLOB_BRACE);
/**
* Todo: Additional logic that will return found class.
*/
}
If a file named bootstrap.php is present in the root of the namespace, it will be automatically included during the initialisation of MODX. There is an example showing you how to add a PSR4 autoloader pointing to the src directory in your namespace: https://docs.modx.com/3.x/en/extending-modx/namespaces#examples
@sdrenth is my previous comment the solution you were looking for?
@JoshuaLuckers untested, but if that works that would be great as well. So I'll close this issue. Thanks for your response