ComposerPHP dependency management tool

Source: Internet
Author: User
Tags composer install
: This article mainly introduces the ComposerPHP dependency management tool. if you are interested in the PHP Tutorial, refer to it. Composer is a tool used by PHP to manage dependencies. You can declare the dependent external library (libraries) in your project. Composer will help you install these dependent library files.

Dependency Management:
Composer is not a package manager. Yes, it involves "packages" and "libraries", but it is managed based on each project and installed in a directory of your project (such as vendor. By default, it does not install anything globally. Therefore, this is just dependency management.

This idea is not new, and Composer is strongly inspired by node's npm and ruby's bundler. At that time, there was no similar tool in PHP.

Composer will solve the problem for you as follows:

A) you have a project dependent on several databases.

B) some of these libraries depend on other libraries.

C) you declare what you are dependent on.

D) Composer will find out which version of the packages need to be installed and install them (download them to your project ).


System requirements

To run Composer, PHP 5.3.2 + or later is required. Some sensitive PHP settings and compilation flags are also required, but a warning is thrown for any incompatible installation program.

We will install the package directly from the package source, rather than simply downloading the zip file. you need git, svn, or hg, depending on the version management system used by the package you load.

Composer is multi-platform, and we strive to make it run equally well on Windows, Linux, and OSX platforms.

Installation-Windows


Use the installer

This is the easiest way to install Composer on your machine.

Download and run the Composer-Setup.exe, which will install the latest version of Composer and set environment variables for the system so you can directly use the composer command in any directory.

Manual installation
This enables composer. phar to be installed in the E:/composer Directory:

Cmd

Microsoft Windows [version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C: \ Users \ wangyulu> E:

E: \> cd composer

E: \ composer> php-r "readfile ('https: // getcomposer.org/installer');" | php
#! /Usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: E: \ composer. phar
Use it: php composer. phar

--- After the execution is completed, the composer. phar file will be created ---

E: \ composer> composer-V
'Composer' is neither an internal or external command nor a running program
Or batch files.

--- Execute composer-V to check whether the installation is successful. the preceding error is reported. in this case, you only need to add the file directory where composer. phar is located in the system environment variable ---
--- E: \ composer add to system environment variable ---

E: \ composer> composer-V
Cocould not open input file: E: \ composer. phar-V

--- When you run the command to view the logs, the preceding error is reported. you only need to create a composer. bat file ---

E: \ composer> echo @ php "% ~ Dp0composer. phar "% *> composer. bat

--- At this time, we will find that a composer. bat batch file will be created in the E: \ composer directory ---

E: \ composer> composer-V
Composer version 1.0-dev (ea037305499d300f3a534b36a62abcdd1ba3479d)
0:08:11

--- Execute the above code to find a version number, and then we will install it successfully ---
--- In this case, we use the monolog logging component to write a test case ---

E: \ composer> composer require "monolog/monolog: 1. 2 .*"
./Composer. json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
-Installing monolog/monolog (1.2.1)
Downloading: 100%

Monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages
To a GrayLog2 server)
Monolog/monolog suggests installing ext-amqp (Allow sending log messages to an
MQP server (1.0 + required ))
Monolog/monolog suggests installing ext-mongo (Allow sending log messages to a M
OngoDB server)
Writing lock file
Generating autoload files


--- Execute the above code and we will find that some more files in the E: \ composer directory are as follows :---

The following is the test code:

Require 'vendor/autoload. php '; use Monolog \ Logger; use Monolog \ Handler \ StreamHandler; // create a log channel $ log = new Logger ('personal centermodule '); $ log-> pushHandler (new StreamHandler ('Ur. log', Logger: WARNING); // add records to the log $ log-> addWarning ('information retrieval failed '); $ log-> addError ('Parameter error'); $ log = new Logger ('login registration module '); $ log-> pushHandler (new StreamHandler('your.txt', Logger :: WARNING); $ log-> addWarning ('logon failed'); $ log-> addError ('information retrieval failed ');

The code execution result is as follows:

The above command generates composer. json, which can also be created manually:

Here, manually create a composer. json file and enter the following:

{    "require": {        "monolog/monolog": "1.0.*"    }}

The other is a configuration item of monolog. Finally, we run the following command in E: \ composer>:

Composer install can also install monolog

So far, the case study on the installation of composer and monolog logging tool has ended here. If there are any mistakes in this article, I hope I can point out that I love sharing and life!

The above conceptual text is from composer's Chinese network, and the case is from an individual.

The above introduces the Composer PHP dependency management tool, including the content, and hope to be helpful to friends who are interested in PHP tutorials.

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.