GitHub-How do I install composer in a PHP file and install the dependent libraries automatically?

Source: Internet
Author: User
Tags autoload
is developing the blog plug-in, need to use this project parser, how to reference the project in a php file without composer, or directly in the PHP file to install composer and this library do?

Reply content:

is developing the blog plug-in, need to use this project parser, how to reference the project in a php file without composer, or directly in the PHP file to install composer and this library do?

Use the autoloader, but it is best to use composer, after all, convenient
Https://github.com/WhichBrows ...

function InstallComposer(){    file_put_contents(__DIR__ . '/composer-setup.php', file_get_contents('https://getcomposer.org/installer'));    shell_exec('php composer-setup.php');}function InstallParser(){    shell_exec('php composer.phar require whichbrowser/parser');}

    1. If not used Composer : If the file is less direct, require come in good, if the file involved more, look at the Library namespace usage specification is Psr4 still Psr0 , write a autoload method, automatic introduction of files, can be referenced Composer ClassLoader .

    2. If used Composer , write one directly composer.json and put the required library into require .

      #composer.json"require": {    "php": ">=5.3.3",    "godtail/db": "dev-master" #例子}#然后composer install`#引入autoload文件require '../vendor/autoload.php';

Of course, the recommended use of composer, modular, more convenient.

Install parser First
And then in the file

require 'vendor/autoload.php';

That's it.

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