A php dependency management tool Composer-php Tutorial

Source: Internet
Author: User
Tags composer install
A dependency management tool for PHP Composer 1: Download

curl -sS https://getcomposer.org/installer | php


Or

php -r "readfile('https://getcomposer.org/installer');" | php



2: move to the bin directory and use the composer command each time.

mv composer.phar /usr/local/bin/composer

View version

composer -V



3. composer. json install monolog in the project
The content of the composer. json file is as follows:

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

Use composer install to install and create the vendor, monolog, and monolog directories in the current directory.
Composer generates a file named vendor/autoload. php. You can simply introduce this file and you will get a free automatic loading support.
This makes it easy for you to use third-party code. The project depends on monolog. you can start using this class library like this and they will be automatically loaded.

$log = new Monolog\Logger('name');$log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));$log->addWarning('Foo');

4. download the thinkphp framework and install monolog.

composer create-project topthink/thinkphp myProjectNamecd myProjectNamevim composer.json

Find require
To:

"Require": {"php": "> = 5.3.0", "monolog/monolog": "1. 0. *"}, find http://packagist.phpcomposer.com to https://packagist.phpcomposer.com

Save and exit

composer install


The current directory will
Create the vendor, monolog, and monolog directories in the current directory.
You can introduce vendor/autoload. php in the framework entry file.
You can use it in the framework.

5. obtain the latest dependency version.

    composer update


If you just want to update several packages

    composer update vendor/package vendor/package2


Batch update with wildcards

    composer update vendor/*

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.