如果已经使用PHP框架,Composer的好处 [英] Benefits of Composer if already using a PHP framework

查看:384
本文介绍了如果已经使用PHP框架,Composer的好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dropbox的PHP SDK大胆地建议,应该使用Composer来安装和加载它们的SDK。此外,AWS的PHP SDK的第2版还提供Composer作为安装/加载程序(幸运的是没有偏见)。

Dropbox's PHP SDK heavy-handedly suggests that one should use Composer to install and load their SDK. Also, version 2 of AWS's PHP SDK also offers Composer as a installation/loader (fortunately without the bias).

我使用Codeigniter几个简单的机制来加载模块。它有1)一个内置的供应商文件夹(由CI称为third_party,由Composer称为供应商)。 2)helper和library文件夹控制我创建的模块,例如 $ this-> load-> library(blah_blah); 3 )最后,没有什么可以阻止我为边缘情况写入香草PHP include / requireblah / blah.php;

I'm using the Codeigniter (CI) framework which has several simple mechanisms to load modules. It has 1) a built in "vendor" folder (called "third_party" by CI, "vendor" by Composer). 2) "helper" and "library" folders to control modules I've created, e.g., $this->load->library("blah_blah"); 3) Lastly, nothing prevents me from writing vanilla PHP include/require "blah/blah.php"; statements for edge cases.

我不知道其他PHP框架,但我假设他们以类似的简单方式处理依赖,因为这似乎是使用框架的主要目的之一。

I don't know other PHP frameworks well, but I'd assume they handle dependencies in similarly simple manners as this would seem one of the main purposes of using a framework.

鉴于这一切,它们对于Composer的额外优势是什么?或者替换代码中与我的框架对话的那部分,而不是Composer?

In light of all this, are their additional benefits to Composer beyond what the frameworks provide? Or to replace the parts of my code that talk to my framework with that that would work instead with Composer? In general, am I not understanding something about Composer?

推荐答案

首先阅读 http://getcomposer.org/doc/00-intro.md


Composer解决的问题是:

The problem that Composer solves is this:

a)你有一个依赖于多个库的项目。

a) You have a project that depends on a number of libraries.

b)其中一些库依赖于其他库。

b) Some of those libraries depend on other libraries.

c)你声明你依赖的东西。

c) You declare the things you depend on.

d)Composer找到哪些版本的软件包需要安装
,并安装它们(意味着它会将它们下载到
项目中)。

d) Composer finds out which versions of which packages need to be installed, and installs them (meaning it downloads them into your project).

您可以安装,更新和管理项目的依赖项。另一个有用的功能,你有 autoload.php 文件加载所有库。你不需要再包含文件(任何支持PSR-0命名空间的框架)。

You can install, update and manage dependencies of your project. Another one usefull feature that you got autoload.php file that load all libraries. You never need to include files anymore(with any framework that supports PSR-0 namespacing).

这里是一个文章,介绍如何使用CI作曲家。我相信你可以找到很多文章,因为它是真正方便的使用作曲家。

Here is an article that explains how to use the composer with CI. I am sure that you can find many articles, because it is really convenient ti use a composer.

这篇关于如果已经使用PHP框架,Composer的好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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