如果类映射实际上更快,为什么在编译器中使用PSR-0或PSR-4自动加载? [英] Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?
问题描述
我了解您可以使用PSR标准来定位文件,也可以告诉作曲家一个目录来扫描类。 文档建议使用PSR-4 标准。还有一个选项以便作曲者创建优化的自动加载器,这基本上会生成完整的类映射。那么为什么要使用PSR-4,如果最好的方式加载是一个类映射?
我有意义的保持目录结构,因为这是一个很好的方式组织反正。然而,似乎合乎逻辑的选择是在开发机器上使用PSR-4加载,然后为生产环境使用类映射。这样,您不必在每次创建新类时重新构建类映射,但生产环境会创建一个完整的类,作为部署过程的一部分,而不需要额外调用
./ composer.phar dump-autoload -o
如果类映射实际上更快,为什么在编译器中使用PSR-0或PSR-4自动加载>
因为它更实用。
在生产中,你可以使用一个classmap( composer dumpautoload -o
),因为你不会添加任何新类,但在开发环境中,有趣的是有PSR-0或PSR-4提供的灵活性(即添加新类时没有任何操作)。
更新:,您也可以使用 composer install -o
/ p>
I understand that you can use either a PSR standard to locate files, or tell composer a directory to scan for classes. The documentation recommends using the PSR-4 standard. There is also an option for composer to create an optimized autoloader, which basically generates a full classmap. So why should one use PSR-4 at all if the best way to load is with a classmap?
It makes sense to me to keep the directory structure, since that is a good way to organize anyway. However, it seems like the logical option would be to use PSR-4 loading on development machines, and then classmap for the production environment. That way, you don't have to rebuild your classmap every time you create a new class, but the production environment creates a complete one as a part of the deployment process without an additional call to
./composer.phar dump-autoload -o
Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?
Because it's more practical.
In production, you can use a classmap (with composer dumpautoload -o
) because you won't add any new class, but in dev environment it's interesting to have the flexibility provided by PSR-0 or PSR-4 (i.e. nothing to do when adding new classes).
Update: you can also use composer install -o
, it's simpler.
这篇关于如果类映射实际上更快,为什么在编译器中使用PSR-0或PSR-4自动加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!