Today I saw an introduction to the dependency management tool under PHP, so I learned and tried it:
Environment: win7
1. Installation
1. Confirm that PHP has enabled the openssl module (used when using https URLs);
Modify the environment Variable path, add c:xamppphp
Open the command line, enter:
php -version
Use the cd command to change the current path to the project root directory, and then run the command to download and install:
php -r "readfile('http://getcomposer.org/installer');" | php
curl -sS https://getcomposer.org/installer | php
Go to the project root directory, add the composer.bat text file, and execute it on the command line:
echo @php "%~dp0composer.phar" %*>composer.bat
composer -V
Second example, the project needs to use monolog, a library that outputs logs.
Create the composer.json file in the project, enter the content:
{ "require": { "monolog/monolog": "1.0.*" } }
composer install
Failed to enable crypto failed to open stream: operation failed
After running successfully, the vendor folder will appear in the project folder.
Usage example:
<?php require_once 'vendor/autoload.php'; $log = new Monolog\Logger('name'); $log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING)); $log->addWarning('Foo'); ?>
3. Others
Update self:
The above introduces the use of the PHP dependency management tool Composer, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.