乐趣区

关于php:PHPComposer-介绍

如何装置?

官网地址:Composer (getcomposer.org),目前集体看到的最新版为 2.4.4。

能够先尝试装置官网的介绍一步步操作:

Command-line installation

To quickly install Composer in the current directory, run the following script in your terminal. To automate the installation, use the guide on installing Composer programmatically.

留神:链接对应了类 Unix 零碎的装置伎俩。

php -r "copy('https://getcomposer.org/installer','composer-setup.php');"
unlink('composer-setup.php'); } echo PHP_EOL;"
php -r "if (hash_file('sha384','composer-setup.php') ==='55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') {echo'Installer verified';} else {echo'Installer corrupt'; 
php composer-setup.php
php -r "unlink('composer-setup.php');"

集体在笔记 [[【PHP】PHP 开发必备配置 – Windows]] 中提到过这个工具的装置,这里不再反复介绍。

Composer 命令

Composer 命令的常用命令如下:

查看 Composer 版本

composer --versin

案例:

C:\Users\adong>composer --version
Composer version 2.4.4 2022-10-27 14:39:29

降级将默认升到最新版本

composer self-update

情谊提醒: 版本升级命令将会从官网版本去下载 composer,phar 镜像, 速度将受限!强烈建议全局配置减速镜像

Composer 自我诊断

应用 Composer 进行自我诊断的代码如下:

composer diagnose

参考案例如下:

C:\Users\adong>composer diagnose
Checking platform settings: OK
Checking git settings: OK git version 2.37.0
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking HTTP proxy: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.4.4
PHP version: 7.4.33
PHP binary path: E:\Program Files\php74\php.exe
OpenSSL version: OpenSSL 1.1.1s  1 Nov 2022
cURL version: 7.70.0 libz 1.2.12 ssl OpenSSL/1.1.1s
zip: extension present, unzip not available, 7-Zip not available

分明缓存

分明缓存的命令如下

composer clear

具体案例如下:

C:\Users\adong>composer clear
Cache directory does not exist (cache-vcs-dir):
Clearing cache (cache-repo-dir): C:\Users\adong\AppData\Local\Composer\repo
Clearing cache (cache-files-dir): C:\Users\adong\AppData\Local\Composer\files
Clearing cache (cache-dir): C:\Users\adong\AppData\Local\Composer
All caches cleared.

我的项目更新 composer.lock

composer update --lock

集体测试案例如下:

C:\Users\adong>composer update --lock
Composer could not find a composer.json file in C:\Users\adong
To initialize a project, please create a composer.json file. See https://getcomposer.org/basic-usage

调试

Composer 调试只须要在命令前加上 -vvv 就能够打印出错信息

例如下载 laravel 命名为 blog 的我的项目

composer -vvv create-project laravel/laravel blog

装置依赖包

装置依赖包须要在指定我的项目的根门路执行上面的操作:

composer install

更新依赖包

该命令仅限在我的项目根目录操作

更新所有依赖包

composer update

更新指定依赖包

composer update monolog/monolog

更新多个指定依赖包

composer update monolog/monolog symfony/dependency-injection

依据通配符匹配更新依赖包

composer update monolog/monolog symfony/*

移除依赖包

移除指定依赖包

composer remove monolog/monolog

依据通配符匹配移除依赖包

composer remove monolog/monolog symfony/*

搜寻依赖包

搜寻依赖包:输入包及其形容信息

composer search monolog

应用案例如下:

C:\Users\adong>composer search monolog
monolog/monolog                       Sends your logs to files, sockets, inboxes, databases and various web services
symfony/monolog-bundle                Symfony MonologBundle
symfony/monolog-bridge                Provides integration for Monolog with various Symfony components
symfony/debug-bundle                  Provides a tight integration of the Symfony VarDumper component and the Serv...
maxbanton/cwh                         AWS CloudWatch Handler for Monolog library
easycorp/easy-log-handler             ! Abandoned ! A handler for Monolog that optimizes log me...
theorchard/monolog-cascade            Monolog extension to configure multiple loggers in the blink of an eye and a...
bramus/monolog-colored-line-formatter Colored Line Formatter for Monolog
wazaari/monolog-mysql                 A handler for Monolog that sends messages to MySQL
logentries/logentries-monolog-handler A handler for Monolog that sends messages to Logentries.com.
inpsyde/logzio-monolog                Logz.io integration for Monolog
newrelic/monolog-enricher             Monolog components to enable New Relic Logs
cmdisp/monolog-microsoft-teams        Monolog Handler for sending messages to Microsoft Teams using the Incoming W...
inpsyde/wonolog                       Monolog-based logging package for WordPress.
amphp/log                             Non-blocking logging for PHP based on Amp and Monolog.

只搜寻包,能够增加 --only-name选项,如下所示

composer search --only-name monolog

执行命令的返回后果较多:

依据通配符搜寻依赖包

composer search mono*

案例如下:

C:\Users\adong>composer  search mono*
mead-steve/mono-snag                         Bugsnag integration for monolog. An abstract handler that sends messages to Bugsnag
digikraaft/mono-php                          PHP Implementation of Mono API
codeat3/blade-mono-icons                     A package to easily make use of Mono Icons in your Laravel Blade views.
yzen.dev/mono-processor                      This Processor will display in the logs bread crumbs by which you can more quickly and accurately identify the cause of the error.
remdex/livehelperchat                        Live Helper Chat - live support for your website. Featuring web and desktop clients. Compatible Windows, Linux, Mac. Desktop client powered by QT. Supports mobile phones based on XMPP se...
aedart/athenaeum                             Athenaeum is a mono repository; a collection of various PHP packages
druidfi/mona-plugin                          Mona Composer Plugin for Drupal 7 sites
dbp/relay-mono-connector-payunity-bundle     A PayUnity connector for the mono bundle for the Relay API gateway
dbp/relay-mono-connector-generic-bundle      A generic connector for the mono payment bundle for the Relay API gateway
dbp/relay-mono-connector-campusonline-bundle A CO payment connector for the mono bundle for the Relay API gateway
dbp/relay-mono-bundle                        A payment bundle for the Relay API gateway
timitao/monoa
loicjazon/mono
druidfi/mona                                 ! Abandoned ! Example setup using mona-plugin
vldmr-k/mono-acquiring                       Monobank Acquiring library

查看依赖包

该命令 仅限我的项目根目录 应用

查看 以后我的项目 已装置的依赖包

composer show

依据通配符 以后我的项目 进行筛选

composer show laravel*

查看 以后我的项目 指定依赖包

composer show laravel/tinker 
退出移动版