user3292653
user3292653

Reputation: 622

composer custom autoloader without adding autoload in composer.json

I'm refering to https://getcomposer.org/doc/01-basic-usage.md#autoloading

Probably all of the composer-users will add this into the composer.json to make it load custom namespaces:

{
    "autoload": {
        "psr-4": {"Acme\\": "src/"}
    }
}

In my case my folder structure is completely the same as the namespaces, so \hello\world would refer to a class inside \hello\world. So, is there a way to tell composer he should search inside the directory with the same names like the namespaces, without telling it inside the composer.json? It's unnecessary expense!

Upvotes: 0

Views: 652

Answers (2)

user3292653
user3292653

Reputation: 622

You can do it with a custom autoloader, since PHP can handle multiple autoloaders!

Upvotes: 1

Sven
Sven

Reputation: 70863

No, you can't do that.

If you want to use long paths resembling the exact namespace structure of your class, you can always use PSR-0 instead, which forces you to use these long directory names. But note that this has some slight drawbacks - traversing longer paths takes slightly more time.

Upvotes: 1

Related Questions