Composer PHP Dependency Management tools

Source: Internet
Author: User
Tags autoload php tutorial composer install
Composer is a tool that PHP uses to manage dependency (dependency) relationships. You can declare your dependencies on the External tool Library (libraries) in your project, and 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 on a per-project basis and installed in a directory of your project (for example, vendor). By default it will not install anything globally. Therefore, this is only a dependency management.

This idea is not new and Composer is strongly inspired by node's npm and Ruby S bundler. There was no such tool under PHP at the time.

Composer will solve this problem for you:

A) You have a project that relies on a number of libraries.

b) Some of these libraries depend on other libraries.

c) You declare what you depend on.

d) Composer will find out which version of the package needs to be installed and install them (download them to your project).


System Requirements

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

Instead of simply downloading the zip file, we'll install it directly from the package's source, and you'll need git, svn, or HG, depending on the version management system you're loading the package with.

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

Install-Windows


Using the Setup program

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

Download and run Composer-setup.exe (Https://getcomposer.org/Composer-Setup.exe), which will install the latest version of Composer and set the environment variables for the system, So you can use the composer command directly in any directory.

Manual Installation
This allows the Composer.phar to be installed in the E:/composer directory:

Cmd

Microsoft Windows [version 6.1.7601]
Copyright (c) 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\composer.phar
Use it:php Composer.phar

---this is done, the Composer.phar file is created---

E:\composer>composer-v
' Composer ' is not an internal or external command, nor is it a running program
or batch file.

---then execute composer-v to see if the installation is successful, the above error will be reported, we only need to add the Composer.phar directory in the system environment variable to---
---E:\composer added to the system environment variable---

E:\composer>composer-v
Could not open input file:e:\composer\composer.phar-v

---then execute the view command will report the above error, then only need to create another Composer.bat file can be---

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

---Then we will find that a composer.bat batch file is created in the E:\composer directory---

E:\composer>composer-v
Composer version 1.0-dev (ea037305499d300f3a534b36a62abcdd1ba3479d) 2015-04-24 1
0:08:11

---at this point we execute the above code will find a version number, then we installed successfully---
---Then we write a test case with the Monolog logging component---

E:\composer>composer require "monolog/monolog:1.2.*"
./composer.json has been created
Loading Composer repositories with the 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 A
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 we will find that there are more files in the E:\composer directory 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 hub module '); $log->pushhandler (New Streamhandler (' Your.log ', logger::warning)) ; Add records to the log$log->addwarning (' Get information failed '), $log->adderror (' parameter error '), $log = new Logger (' Login registration module '); $log Pushhandler (New Streamhandler (' Your.txt ', logger::warning)), $log->addwarning (' Login failed '); $log->adderror (' Failed to obtain information ');    

The result of the code operation is as follows:

The previous build Composer.json is generated with commands, but can also be created manually:

Here, manually create a Composer.json to enter as follows:

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

Other This is a Monolog configuration item, and finally we execute it in e:\composer>:

The composer install can also be installed Monolog

This is the end of the case test for the composer installation and Monolog logging tool. If there is a wrong place in the text, hope can point out, love to share, love life!

The above conceptual text originates from composer Chinese network, the case originates from individual.

The above describes the composer PHP dependency management tools, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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