Github-how to install composer in the PHP file and automatically install the dependent library?

Source: Internet
Author: User
Tags composer install
We are developing a blog plug-in. we need to use this project Parser. how can we reference this project in the PHP file in an environment without composer, or directly install composer and this library in the PHP file? We are developing a blog plug-in. we need to use this project Parser. how can we reference this project in the PHP file in an environment without composer, or directly install composer and this library in the PHP file?

Reply content:

We are developing a blog plug-in. we need to use this project Parser. how can we reference this project in the PHP file in an environment without composer, or directly install composer and this library in the PHP file?

You can use the automatic loader, but it is better to use composer, which is convenient after all.
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 you do not useComposer: If there are few files,requireIf many files are involved, the usage specification of the library namespace isPsr4OrPsr0, WriteautoloadMethod to automatically introduce files. For more information, seeComposerOfClassLoader.

  2. If you useComposer, Directly writecomposer.json, Put the required Libraryrequire.

    # Composer. json "require": {"php": "> = 5.3.3", "godtail/db ": "dev-master" # Example} # then composer install '# introduce the autoload file require '.. /vendor/autoload. php ';
Of course, Composer is recommended for componentization, which is more convenient.

Install parser first
And then in the file

require 'vendor/autoload.php';

In this way, you can

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.