Home > Backend Development > PHP Tutorial > github - How to install composer in a php file and automatically install dependent libraries?

github - How to install composer in a php file and automatically install dependent libraries?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-10-11 14:23:16
Original
1443 people have browsed it

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

Reply content:

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

You can just use an autoloader, but it’s better to use composer, it’s more convenient after all
https://github.com/WhichBrows...

<code>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');
}</code>
Copy after login

  1. If you don’t use Composer: If there are few files, just require comes in. If there are many files involved, check whether the namespace usage specification of the library is Psr4 or Psr0, and write an autoload method. To automatically import files, you can refer to ClassLoader of Composer.

  2. If you use Composer, just write a composer.json and put the required libraries into require.

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

Of course it is recommended to use Composer, which is componentized and more convenient.

Install parser first
and then add the file

<code>require 'vendor/autoload.php';</code>
Copy after login

That’s it

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
github - git checkout -f problem
From 1970-01-01 08:00:00
0
0
0
css - hexo+github build blog
From 1970-01-01 08:00:00
0
0
0
How to upload json files to github repository?
From 1970-01-01 08:00:00
0
0
0
How to delete released Releases on github
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template