Composer vs Symfony 2自动加载器 [英] Composer vs Symfony 2 autoloader

查看:326
本文介绍了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?

Symfony自动加载器提供的功能是否在Composer自动加载器中找不到?

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.

这篇关于Composer vs Symfony 2自动加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆