About composer use record sharing

Source: Internet
Author: User
Tags autoload yii

1. Introduction

Composer is a PHP-based code package dependency management tool. It is not a package management tool that involves "packages" and "libraries", which are managed on a project basis and installed somewhere in the project (for example, vendor). So composer is just a dependency management tool.

2.Windows Installation

Installation steps:

First step: Download and run the Composer-setup.exe, follow the instructions to complete the installation ( need to configure the PHP environment );
The second step: Open the Command Line window, execute composer-v, see the version information after the installation is complete;

3. Project installation (for Yii, for example)

3.1 Installing Yii

The first step: Execute the following command

Composer global require "fxp/composer-asset-plugin:^1.3.1" composer Create-project--prefer-dist--stability=dev Yiisoft/yii2-app-basic Basic Note: The first command installs Composer asset plugin, which is required by Composer to manage Bower and NPM packages, and this command takes effect globally. The second command installs the latest development version of YII.    The second step: Visit Yii, you can see the normal page description installation success. 3.2 Installing the Yii2-mongodb extension

The first step: CD to YII2 project directory, execute the following command
Composer require--prefer-dist Yiisoft/yii2-mongodb
Step two: After the installation is complete, check to see if Vendor\yiisoft created the Yii2-mongodb and if it was created, the installation succeeds.

3.3 Composer.json File

Configuration Description:
1.require defines which packages are required for the project, ~2.0.14 represents >=2.0.14 and <3.0
2.autoload defines the automatically loaded file, psr-4 represents the automatic load specification following the PSR-4 namespace
The name of the 3.name package
4. The configuration entry for the example repositories means that a package is loaded from composer https://asset-packagist.org
5.type defines a resource type, and the example defines an extension of yii
Example:

{"Name": "Yiisoft/yii2-mongodb", "description": "MongoDB Extension for the YII framework", "keywords": ["Yii2",         "Mongo", "MongoDB", "Active-record", "Gridfs"], "type": "Yii2-extension", "License": "Bsd-3-clause", "support": {         "Issues": "Https://github.com/yiisoft/yii2-mongodb/issues", "Forum": "http://www.yiiframework.com/forum/", "wiki": "http://www.yiiframework.com/wiki/", "IRC": "Irc://irc.freenode.net/yii", "source": "https ://github.com/yiisoft/yii2-mongodb "}," authors ": [{" Name ":" Paul Klimov "," email ":" Klimov.paul@gmail.com "}]," require ": {" Yiisoft/yii2 ":" ~2.0.14 "," Ext-mongodb ":" &G t;=1.0.0 "}," repositories ": [{" Type ":" Composer "," url ":" Https://asset-packa                 Gist.org "}]," AutoLoad ": {" psr-4 ": {" yii\\mongodb\\ ":" Src "}}," Extra ": { "Branch-alias":{"Dev-master": "2.1.x-dev"}}} 


3.4 Composer Common command line

Composer-v Details of the feedback information
Composer-h Displays help information.
Composer-q prohibit output of any information
Composer-n Don't ask any interaction questions
PHP Composer.phar Install installation
PHP composer.phar Update updates
PHP Composer.phar require affirm dependency

Related recommendations:

Composer example analysis of automatic loading

A detailed introduction to composer

Laravel steps to install with composer under Windows

Related Article

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.