Composer study notes

Source: Internet
Author: User
Composer learning notes Composer is the best dependency management tool in php, so as a literary phper, you must get it up.

Getting Started = getting stuck?

Many of my friends don't want to get started with this product. The most important reason is that I didn't want to get started with this product before.Wall.

When talking about it, it was tears. at that time, all kinds of images were useless. even if they could be used, they were basically character-oriented and basically unstable.

Even at that time, I had to manually install various packages and encountered N pitfalls, such as manually downloading dependencies and importing them manually .. Alas. It hurts a lot more than when looking for various types of plug-ins.

Install Composer

In fact, it is easy to say that it is troublesome and troublesome, because it is necessary to divide * nix and win platforms, so you can directly lose the connection.

Install-* nix

Installation-Windows

Check whether the installation is successful.

$ composer -V

Output something like this

Composer version 1.0-dev (1a5445132f1cbd366294924dc2fd0114dd4c843a) 2016-03-14 17:39:12

OK. Congratulations, you can proceed.

What is an image?

Tianchao programmers who do not know the image are not good coders.

Due to the powerful GFW, we were unable to access some excellent foreign websites. Therefore, various image servers were born to help US import the resources on these websites to China, you can download these resources by modifying a configuration. These resources are synchronized on a regular basis, so you do not need to worry about resource stale issues.

It is because of this that N people are discouraged and have never dared to use Composer. it is a pity that such a good tool is used.

Currently, the only stable and stable Composer image is only Packagist/Composer's full-scale image in China, although occasionally exhausted.

It is also easy to use. we recommend that you configure images globally.

Open the command line window (windows user) or console (Linux or Mac user) and execute the following command:

$ composer config -g repo.packagist composer https://packagist.phpcomposer.com

OK. after the image problem is fixed, you can get started with Composer.

Use Composer

Although the official tutorials are comprehensive, they are cool. For example, the first example is to manually create composer. json, write the dependencies, and install the module package in json through composer install. Although you can't say no, few people are using it because it is too troublesome.

For example, I want to install yii2.

The official Yii installation method is to first install the Composer Asset plug-in:

$ php composer.phar global require "fxp/composer-asset-plugin:~1.1.1"

Then install the basic application template:

$ php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.7

Or install an advanced application template:

$ php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.7

However, I have encountered countless such errors.

Failed to decode response: zlib_decode(): data errorRetrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

Baidu later found that the -- prefer-dist parameter can be added.

$ php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.7 --prefer-dist

PS: If you get stuck during installation, the image may be exhausted. just try it several times.

OK. after reading the document, you can find the -- prefer-source and -- prefer-dist parameters. two methods are available for downloading the package: source (source code) and dist (release ), of course we want to install the dist (released) version.

OK. this is the installation. I want to add a new plug-in. how can this problem be solved by the new dependency?

Then, let's break it back... ('{ω .')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.