revolution icon indicating copy to clipboard operation
revolution copied to clipboard

Provide option to load autoloadable controllers for extras

Open sdrenth opened this issue 3 years ago • 1 comments

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.
     */
}

sdrenth avatar Aug 09 '22 09:08 sdrenth

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

JoshuaLuckers avatar Aug 12 '22 14:08 JoshuaLuckers

@sdrenth is my previous comment the solution you were looking for?

JoshuaLuckers avatar Dec 26 '22 12:12 JoshuaLuckers

@JoshuaLuckers untested, but if that works that would be great as well. So I'll close this issue. Thanks for your response

sdrenth avatar Dec 26 '22 15:12 sdrenth