Benefits of Composer if already using a PHP framew

2019-08-15 04:01发布

问题:

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).

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.

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.

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?

回答1:

First of all read http://getcomposer.org/doc/00-intro.md

The problem that Composer solves is this:

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

b) Some of those libraries depend on other libraries.

c) You declare the things you depend on.

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

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).

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.