其中 autoload 有两种自定义的配置
1 classmap 数组 为文件目录地址 可以引入目录中的php文件
2 files 数组 为文件地址 可以引入具体的php文件
通过这样的设置 可以替换相同命名空间,相同类名 的文件
如 cmf\lib 中的 Upload.php 该文件 被方式 1引入 可以替换 tp自带的upload 文件(vendor\thinkcmf\cmf\src\lib\Upload.php) 其他原本调用该文件的文件 直接修改为新文件
可以实现 无侵入式的代码替换
{
"name": "thinkcmf/thinkcmf",
"description": "ThinkCMF based on ThinkPHP 6.0 , it is a free and open source Content Management Framework(CMF)",
"type": "project",
"keywords": [
"cmf",
"ThinkCMF",
"framework",
"ThinkPHP",
"ORM"
],
"homepage": "http://www.thinkcmf.com/",
"license": "MIT",
"authors": [
{
"name": "catman",
"email": "catman@thinkcmf.com"
},
{
"name": "Xia",
"email": "449134904@qq.com"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.0.0",
"ext-json": "*",
"ext-curl": "*",
"ext-pdo": "*",
"thinkcmf/cmf": "^6.0.0",
"thinkcmf/cmf-app": "^6.0.0",
"thinkcmf/cmf-route": "^6.0.0",
"topthink/framework": "^6.0.0",
"thinkcmf/think-view": "~1.0.15",
"topthink/think-orm": "^2.0",
"topthink/think-captcha": "^3.0",
"thinkcmf/cmf-install": "^6.0.0",
"thinkcmf/cmf-api": "^6.0.0",
"thinkcmf/cmf-appstore": "^1.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2",
"topthink/think-trace": "^1.0"
},
"autoload": {
"psr-4": {
"app\\": "app",
"api\\": "api",
"plugins\\": "public/plugins",
"themes\\": "public/themes"
},
"psr-0": {
"": "extend/"
},
"classmap": [
"cmf/lib/",
"cmf/src/",
"kalun/",
"kalun/www/"
]
},
"extra": {
"think-config": "data/config"
},
"config": {
"preferred-install": "dist",
"vendor-dir": "vendor"
},
"scripts": {
"post-autoload-dump": [
"@php think service:discover",
"@php think vendor:publish"
]
},
"repositories": {
}
}
本文介绍了Composer中`autoload`的两种自定义配置:classmap和files,用于引入PHP文件。通过设置,可以替换相同命名空间和类名的文件,例如用cmflibUpload.php替换tp自带的upload文件,实现无侵入式的代码替换。
323





