BlueXIII's Blog

热爱技术,持续学习

0%

Composer学习笔记

参考文档

常用操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 查看版本
composer --version

# 升级到最新版本
composer self-update

# 版本降级为1.x最新
composer self-update --1

# 版本降级为1.X指定版本
composer self-update 1.10.20

# 版本回滚到2.X
composer self-update --rollback

# 配置阿里云镜像源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
composer config --unset repos.packagist

# 调试参数
-vvv

# 安装依赖包(composer.json配置)
composer install

# 安装依赖包(忽略系统依赖)
composer install --ignore-platform-reqs

# 直接安装依赖
composer require monolog/monolog

# 直接删除依赖
composer remove monolog/monolog

# 忽略内存限制
COMPOSER_MEMORY_LIMIT=-1 composer require jenssegers/mongodb

# 更新依赖
composer update

# 清理缓存
rm -rv vendor
rm composer.lock
composer clearcache

# 其它
composer search monolog # 搜索
composer show 列出所有已经安装的包
composer dump-autoload
php artisan optimize

杂项

  • Laravel6.X项目,应使用1.X版本compser,避免install时报错

composer install 报错

1
2
3
4
> @php artisan package:discover
In PackageManifest.php line 122:
Undefined index: name
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

https://exerror.com/packagemanifest-php-line-122-undefined-index-name/

115行左右

1
2
3
# $packages = json_decode($this->files->get($path), true);
$installed = json_decode($this->files->get($path), true);
$packages = $installed['packages'] ?? $installed;