composer 常用命令
1.查看版本号
composer -V
2.更新
composer self-update
3.切换阿里源
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
4.创建或更新 composer 的自动加载器
composer dumpautoload
5.自定义类的自动加载
{
"autoload": {
"classmap": ["lib/", "src/", "app/Test1.php"]
}
}
6.自定义其他非类文件的自动加载
{
"autoload": {
"files": ["config/database.php", "func/helper.php"]
}
}
7.PSR-4 类命名空间映射到类文件所在的路径,类名与类文件同名,且文件中只有一个类
文件结构
acme-log-writer
lib
File_Writer.php
composer.json
{
"psr-4": {
"Acme\\Log\\Writer\\": ["acme-log-writer/lib/"]
}
}
File_Writer.php
namespace Acme\Log\Writer;
class File_Writer
{
public static function show()
{
return '当前类名:' . __CLASS__;
}
}
echo \Acme\Log\Writer\File_Writer::show() . '<br>';
8.第三方组件库/包下载
平台:https://packagist.org/
下载方式
1.终端运行 composer require youngyezi/captcha
2.json内手工添加
"require": {
"youngyezi/captcha": "6.0.*"
}
终端运行composer install安装
9.其他常用的指令
- 更新所有包或指定的包: `composer update 空/*/包名列表空格分隔`
- 移除包: `composer remove 包`
- 查看所有包: `composer show`
- 查看指令帮助信息: `composer help install`
- 更多指令: `composer`回车后可以看到