Question

Is there a way to get the composer autoloader instance inside a Symfony2 Controller?

Was it helpful?

Solution

Yes - there is a way.

And assuming that you want to know how to actually get the loader then you can do this in your controller:

class MyController
    function myAction()
    {
        die(get_class($GLOBALS['loader'])); // Composer\Autoload\ClassLoader

Should you do this? Probably not. In most cases you can tweak the loader in the app/autoload.php file.

OTHER TIPS

Using the $GLOBALS did not work for me, but you can also get it like this:

$autoload_functions = spl_autoload_functions();
$loader = $autoload_functions[0][0];

this assumes that "autoload.php" has been required, AND that it is configured to prepend the composer classloader to other classloaders (the default).

NOTE: I am not saying this is good style.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top