Composer Application (i) automatic loading

Source: Internet
Author: User
Before applying, make sure you have composer installed.

Installation procedure, you can refer to http://docs.phpcomposer.com/00-intro.html

1) Configure the Composer.json file

To start using Composer in your project, you only need a Composer.json file. This file contains the dependencies of the project and some other metadata.

{    "name": "Lizhibin331313869/test",              GitHub account name    "version": "0.1.0",                           //Project version    "  Require": {  //require key tells Composer which packages your project needs to rely on.        "Monolog/monolog": "1.2.*"    }}

After the configuration is complete, execute composer install, after execution completes, will generate the vendor folder in the current directory, as well as the Composer.lock file, the lock file contains the version of the dependent package just downloaded, ensure that each project installation is using the same version of the dependency package.

This means that anyone who builds a project will download the exact same dependency as the specified version. Your continuous Integration server, production environment, other developers on your team, everything, everyone uses the same dependencies to mitigate the impact of potential errors on your deployment. Even if you are developing your project on your own, you can rest assured that you will be able to continue working even if you have already released many new versions of your dependencies since then within six months.

2) Use Monolog

For the library's automatic loading information, Composer generates a vendor/autoload.php file. You can simply introduce this file and you will get a free auto-load support.

Use Monolog\logger;use Monolog\handler\streamhandler; require ' vendor/autoload.php '; $loggerModel =new Logger (' test '); $log = new Logger (' name '); $log->pushhandler (new Streamhandler (' D:\test\log\monolog.txt ', logger::warning));//Add Records to the log$log->addwarning (' Foo ', Array ( ' Foo is null! '); $log->adderror (' Bar ');

Reference: http://docs.phpcomposer.com/01-basic-usage.html

The above describes the composer application (i) automatic loading, including the content of the Require,github, I hope that the PHP tutorial interested in a friend helpful.

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