Composer 和 Parsedown - Class 'UserFrosting\Parsedown' 未找到

Composer & Parsedown - Class 'UserFrosting\\Parsedown' not found

我成功地安装了 Parsedown 使用 composer 和

    "require": {
        ...
        "erusev/parsedown": "^1.6"
    },

并将class路径添加到自动加载部分

"autoload": {
    "classmap" : [
        "controllers", "middleware", "models", "plugins", "vendor/erusev/parsedown"
    ]
}

但是当我尝试执行这一行时...

    $Parsedown = new Parsedown();

...我最终遇到了这个错误:

Class 'UserFrosting\Parsedown' not found

运行 php composer.phar dump-autoload 没有帮助。

我在这里错过了什么?为什么在 UserFrosting 下需要 Parsedown - UserFrosting\Parsedown?

这里是完整的 composer.json:

{
    "name": "userfrosting/UserFrosting",
    "type": "project",
    "description": "A secure, modern user management system for PHP.",
    "keywords": ["php user management", "usercake", "bootstrap"],
    "homepage": "https://github.com/userfrosting/UserFrosting",
    "license" : "MIT",
    "authors" : [
        {
            "name": "Alexander Weissman",
            "homepage": "https://alexanderweissman.com"
        }
    ],
    "require": {
        "birke/rememberme" : "1.0.4",    
        "illuminate/database" : "5.0.33",
        "league/csv": "8.1.*",
        "nikic/php-parser" : "~1",
        "php" : ">=5.4.0",
        "phpmailer/phpmailer" : "5.2.10",        
        "twig/twig" : "~1.0",
        "slim/slim" : "2.*",
        "slim/views" : "0.1.3",
        "userfrosting/fortress" : "1.*",
        "wikimedia/composer-merge-plugin": "~1",
        "components/highlightjs": "9.8.0",
        "aws/aws-sdk-php": "3.*",
        "erusev/parsedown": "^1.6"
    },
    "extra": {
        "merge-plugin": {
            "include": [
                "plugins/*/composer.json"
            ],
            "recurse": true,
            "replace": false,
            "merge-dev": true,
            "merge-extra": false
        }
    },
    "autoload": {
        "classmap" : [
            "controllers", "middleware", "models", "plugins", "vendor/erusev/parsedown"
        ]
    }
}

看起来您正在尝试在具有命名空间 UserFrosting 的 class 中执行这行代码 $Parsedown = new Parsedown();

在 php 文件的顶部添加一个 use 块,如下所示:use Parsedown;(这应该在名称空间声明之后),或者在 class 使用时的名称,例如:$Parsedown = new \Parsedown();。后者将开始在根命名空间中寻找这个 class。

您不需要将此 class 添加到 composer.json 文件的自动加载 classmap 部分。如果一个包被 composer 拉取,composer 会在 运行 dump-autoload.

之后自动将所有内容添加到 autoloader