简体   繁体   中英

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!

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.

您可以使用自定义自动加载器,因为PHP可以处理多个自动加载器!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM