1

我设法使用作曲家安装Parsedown

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

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

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

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

    $Parsedown = new Parsedown();

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

找不到类“UserFrosting\Parsedown”

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

我在这里想念什么?为什么在 UserFrosting - UserFrosting \Parsedown 下需要 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"
        ]
    }
}
4

1 回答 1

3

看起来您正试图$Parsedown = new Parsedown();在具有 namespace 的类中执行这行代码UserFrosting

要么use在你的 php 文件的顶部添加一个块,像这样:(use Parsedown;这应该在命名空间声明之后),或者在你使用它时在类名之前输入一个反斜杠,像这样:$Parsedown = new \Parsedown();. 后者将开始在根命名空间中查找此类。

您不需要将此类添加到composer.json文件的自动加载类映射部分。如果一个包被 composer 拉取,composer 会在运行 dump-autoload 后自动将所有内容添加到 autoloader。

于 2016-11-23T10:50:32.490 回答