Useful PHP Dependency management Tools composer Novice Tutorials

Source: Internet
Author: User
Tags get ip spl readfile string methods composer install

PHP Dependency management Tools composer Novice Tutorials

Composer is a dependency management tool for PHP. It agrees with the code base that you declare the project depends on, and it installs them for you in your project.

Dependency Management

Composer is not a package manager.

Yes, it involves "packages" and "libraries", but it is managed on a per-project basis and is installed in one of your project's folders (such as vendor).

By default it will not be installed globally, regardless of the thing. Therefore, this is only a dependency management.

The 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:
You have a project that relies on a number of libraries.
Some of these libraries depend on other libraries.
You declare what you depend on.
Composer will find out which version number of the package needs to be installed. and install them (download them to your project).



References: http://www.lai18.com/content/319715.html
Http://docs.phpcomposer.com/00-intro.md
declaring dependencies

For example, you are creating a project and you need a library to do the logging. You decide to use Monolog. To add it to your project, all you need to do is create a Composer.json file. It describes the dependencies of the project.

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

We just need to point out that our project needs some monolog/monolog packages, starting from 1.2 regardless of the version number.

System Requirements

PHP 5.3.2+ above version number is required to execute Composer. Some sensitive PHP settings and compilation flags are also required, but a warning will be thrown for any incompatible installation program.

Instead of simply downloading the zip file, we will install it directly from the source of the package, and you need git, svn, or HG, depending on the version number management system you are using to load the package.

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

Linux/unix under Installation

Partial installation


To really get Composer. We need to do two things.

First install Composer (the same, which means it will be downloaded to your project):

Curl-ss Https://getcomposer.org/installer | Php

Note: If the above method fails for some reason, you can also download the installer via PHP >:

Php-r "ReadFile (' Https://getcomposer.org/installer ');" | Php

This will check for some PHP settings. Then download Composer.phar to your working folder.

This is a binary file of Composer.

This is a PHAR package (PHP archive), which is a PHP archive format that helps users run some operations on the command line.

You can specify the installation folder for Composer by using the--install-dir option (it can be an absolute or relative path):

Curl-ss Https://getcomposer.org/installer | PHP----install-dir=bin

Global Installation

You can place this file wherever you are. Suppose you put it in the PATH folder of the system. You'll be able to access it in the global interview.

In Unix-like systems, you can even use PHP without a prefix.



You can run these commands to let composer make a global call on your system:

Curl-ss Https://getcomposer.org/installer | PHPMV Composer.phar/usr/local/bin/composer

Note: Assume that the appeal command failed due to permission execution. Please use sudo again to try to execute the MV Line command.

Now it is only necessary to execute the composer command to be able to use composer without the need to enter PHP Composer.phar.



Global installation (on OSX via homebrew)

Composer is part of the homebrew-php project.



Brew Updatebrew Tap josegonzalez/homebrew-phpbrew tap homebrew/versionsbrew install php55-intlbrew install Josegonzalez /php/composer

Install under Windows

Using the Setup program


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

Download and execute composer-setup.exe. It will install the latest version number of the Composer. and set up the environment variables of the system, so you can use the composer command directly under whatever folder.



Manual Installation

Set the system's environment variable PATH and execute the install command to download the Composer.phar file:

C:\USERS\USERNAME>CD c:\binc:\bin>php-r "ReadFile (' Https://getcomposer.org/installer ');" | Php

Note: Assume that you receive the ReadFile error prompt. Please use the HTTP link or open Php_openssl.dll in php.ini. Create a new file Composer.bat under the Composer.phar Sibling folder:

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

Close the current command line form. Open a new command line form to test:

C:\users\username>composer-vcomposer version 27d8904

using Composer

Today we will use Composer to install the dependencies of the project.

To resolve and download dependencies. Please run the install command:

PHP Composer.phar Install

Suppose you have a global installation. And there is no Phar file in the current folder. Use the following command instead:

Composer Install

Continue with the example above. This will download the Monolog to the Vendor/monolog/monolog folder.

Take your own initiative to load

In addition to the library download. Composer also prepared an initiative to load the file himself. It can load all the class files in the library that Composer downloaded.

Use it. You just need to add the following line of code to your project's boot file:

Require ' vendor/autoload.php ';

Now we are able to use the Monolog!



Extended Reading

Advanced knowledge of PHP series of technical Articles to organize the collection

1session mechanism specific explanations and session related applications

2php Weather Forecast code example from the Central Meteorological Observatory coverage nationwide

3smarty self-defined function Htmlcheckboxes use method instance

4PHP session may cause concurrency problems

5PHP callback function usage and considerations

6 Friends net about QQ related PHP code (study QQ excellent information)

Use Imagick to generate PSD file thumbnail tutorial in 7PHP

8PHP implements the method of saving browsing history page URLs to cookies

The method of using session in 9php to prevent users from illegally logging in the background

10 using Xdebug to analyze PHP programs to identify performance bottlenecks

11PHP Dependency management Tools composer Novice Tutorials

12PHP developers should know 5 tips for Composer

13PHP implementation of the Get_headers function with timeout function

Get IP and geolocation class sharing in 14PHP

15php using Iconv to solve the problem of Chinese truncation

Support Path_info specific explanations under 16nginx

24 Cool PHP Libraries that 17PHP developers should know about (micro-framework)

How does 18HHVM improve PHP performance?

19php ways to turn on multiple processes

20PHP Exception Handling

21PHP Daemon Process Instance

Analysis of pipeline communication example of 22PHP multithreading programming

23PHP multi-process processing parallel Processing Task instance

24PHP implementing multi-process parallel task handlers using QPM

Analysis of multi-thread instances in 25PHP multiple threads

26xhprof Installation && Use

27 Recommended 11 PHP frameworks for Developers

28Cookie and session differences-summarize very good Articles

29PHP Self-brought session hidden Trouble (session file exclusive lock causes blockage)

30php compression and decompression of string methods

31php method of implementing plug-in mechanism using reflection

Data structure doubly linked list of 32PHP SPL standard library (spldoublylinkedlist)

33PHP SPL standard library data structure fixed length array (splfixedarray)

34XSS Attack Knowledge Primer Finishing

35PHP SPL standard library data structure queue (Splqueue) and Priority queue (Splpriorityqueue)

Streams in 36PHP specific introduction

37php file system permissions issues and workarounds in fastcgi execution

38PHP Performance Analysis tool Xhprof installation Tutorial

3,900 Degrees Project Division the Implementation principle and performance analysis of PHP function (II.)

4,000 degrees Project Division the Implementation principle and performance analysis of PHP function (III.)

4,100 Degrees Project Division the Implementation principle and performance analysis of PHP functions (I.)

42 correct PHP match UTF-8 Chinese normal form

A summary of the series functions of sockets in 43php

44PHP Socket Programming Specific explanation

45 How to hide PHP versions on a Linux system server

Useful PHP Dependency management Tools composer Novice 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.