如何装置?
官网地址: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 --versionComposer version 2.4.4 2022-10-27 14:39:29
降级将默认升到最新版本
composer self-update
情谊提醒: 版本升级命令将会从官网版本去下载composer,phar镜像,速度将受限!强烈建议全局配置减速镜像
Composer 自我诊断
应用Composer 进行自我诊断的代码如下:
composer diagnose
参考案例如下:
C:\Users\adong>composer diagnoseChecking platform settings: OKChecking git settings: OK git version 2.37.0Checking http connectivity to packagist: OKChecking https connectivity to packagist: OKChecking HTTP proxy: OKChecking github.com rate limit: OKChecking disk free space: OKChecking pubkeys:Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952OKChecking composer version: OKComposer version: 2.4.4PHP version: 7.4.33PHP binary path: E:\Program Files\php74\php.exeOpenSSL version: OpenSSL 1.1.1s 1 Nov 2022cURL version: 7.70.0 libz 1.2.12 ssl OpenSSL/1.1.1szip: extension present, unzip not available, 7-Zip not available
分明缓存
分明缓存的命令如下
composer clear
具体案例如下:
C:\Users\adong>composer clearCache directory does not exist (cache-vcs-dir):Clearing cache (cache-repo-dir): C:\Users\adong\AppData\Local\Composer\repoClearing cache (cache-files-dir): C:\Users\adong\AppData\Local\Composer\filesClearing cache (cache-dir): C:\Users\adong\AppData\Local\ComposerAll caches cleared.
我的项目更新 composer.lock
composer update --lock
集体测试案例如下:
C:\Users\adong>composer update --lockComposer could not find a composer.json file in C:\Users\adongTo 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 monologmonolog/monolog Sends your logs to files, sockets, inboxes, databases and various web servicessymfony/monolog-bundle Symfony MonologBundlesymfony/monolog-bridge Provides integration for Monolog with various Symfony componentssymfony/debug-bundle Provides a tight integration of the Symfony VarDumper component and the Serv...maxbanton/cwh AWS CloudWatch Handler for Monolog libraryeasycorp/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 Monologwazaari/monolog-mysql A handler for Monolog that sends messages to MySQLlogentries/logentries-monolog-handler A handler for Monolog that sends messages to Logentries.com.inpsyde/logzio-monolog Logz.io integration for Monolognewrelic/monolog-enricher Monolog components to enable New Relic Logscmdisp/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 Bugsnagdigikraaft/mono-php PHP Implementation of Mono APIcodeat3/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 packagesdruidfi/mona-plugin Mona Composer Plugin for Drupal 7 sitesdbp/relay-mono-connector-payunity-bundle A PayUnity connector for the mono bundle for the Relay API gatewaydbp/relay-mono-connector-generic-bundle A generic connector for the mono payment bundle for the Relay API gatewaydbp/relay-mono-connector-campusonline-bundle A CO payment connector for the mono bundle for the Relay API gatewaydbp/relay-mono-bundle A payment bundle for the Relay API gatewaytimitao/monoaloicjazon/monodruidfi/mona ! Abandoned ! Example setup using mona-pluginvldmr-k/mono-acquiring Monobank Acquiring library
查看依赖包
该命令仅限我的项目根目录应用
查看以后我的项目已装置的依赖包
composer show
依据通配符以后我的项目进行筛选
composer show laravel*
查看以后我的项目指定依赖包
composer show laravel/tinker