1
votes

I'm having trouble understanding with doesn't Composer autoloads the packages I required.

My current composer.json file has the following:

{
    "require": {
        "atlas/orm": "@dev"
    },
    "require-dev": {
        "atlas/cli": "@dev"
    }
}

It was supposed to generate a Namespace in the /vendor/composer/autoload_namespaces.php file. But it doesn't. The file only has the following:

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Psr\\Log\\' => array($vendorDir . '/psr/log'),
);

Of course, when I try to use the "require DIR . '/vendor/autoload.php';" to autoload the package and then use its classes, it does not work. Any idea on how can I solve this?

1
Have you issued a 'composer install' or 'composer update' command to generate the auto loaders?vascowhite
@vascowhite, yes I did issued a composer install command. It did generate the autoload files, but for example the autoload_namespaces.php file, only has the nformation above.Cláudio Ribeiro

1 Answers

1
votes

For requiring in all of the installed dependencies, you have to require 'autoload.php'. For autoloading(PSR-4), in the composer.json file, you have to give a name under which everything will be namespaced and the folder name from which files will be autoloaded.

"Namespace_name\\":"folder_name"

Note: The backslash after the namespace_name needs to be escaped, hence the extra backslash.

Then run composer dump-autoload -o