Composer vs Symfony 2 自动加载器
我开始在一个项目中使用 Composer,在这个项目中,我历来将所有依赖项都置于版本控制之下.
I'm starting to use Composer in a project, in which I historically had all the dependencies under version control.
这个项目目前使用 Symfony 2 自动加载器.因为 Composer 带有自己的自动加载机制(vendor/autoload.php
),这让我想知道我是否还需要使用 Symfony ClassLoader.
This project currently uses the Symfony 2 autoloader. Because Composer comes with its own autoloading mechanism (vendor/autoload.php
), that makes me wonder if I still need to use the Symfony ClassLoader.
我假设我也可以使用 Composer 自动加载器来自动加载我的项目类:
I assume that I could just use the Composer autoloader to autoload my project classes as well:
$loader = require 'vendor/autoload.php';
$loader->add('MyProject', 'src');
在整个项目中使用 Composer 自动加载器有什么缺点吗?
Is there any drawback in using the Composer autoloader for the whole project?
我在 Composer 自动加载器中找不到 Symfony 自动加载器提供的功能吗?
Are there features the Symfony autoloader offers that I won't find in the Composer autoloader?
推荐答案
你可以只需要 composer 自动加载器.它唯一缺少的功能是 ApcClassLoader,它可以加快 APC 的速度,但会引入一些复杂性(部署时必须清除缓存).使用 composer 的 -o 标志(在安装或运行 dump-autoload 时)将为您提供一个类映射,它在速度方面或多或少等同于 APC,但没有复杂性.
You can just require the composer autoloader. The only feature it lacks is the ApcClassLoader which speeds things up with APC but introduces some complexity (you have to clear the cache when deploying). Using composer's -o flag (when installing or running dump-autoload) will give you a classmap one which is more or less equivalent to APC in terms of speed but without the complexity.
相关文章