Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top