composer autoload 自定义导入配置

本文介绍了Composer中`autoload`的两种自定义配置:classmap和files,用于引入PHP文件。通过设置,可以替换相同命名空间和类名的文件,例如用cmflibUpload.php替换tp自带的upload文件,实现无侵入式的代码替换。

其中 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": {
    }
}
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值