Composer vs Symfony 2 自动加载器

Composer vs Symfony 2 autoloader(Composer vs Symfony 2 自动加载器)
本文介绍了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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)