Luke G Luke G - 17 days ago 9
PHP Question

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

I managed to install Parsedown using composer with

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


and added the class path to the autoload section

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


But when I try to execute this line...

$Parsedown = new Parsedown();


... I end up with this error:


Class 'UserFrosting\Parsedown' not found


Running php composer.phar dump-autoload did not help.

What am I missing here? Why Parsedown is expected under UserFrosting - UserFrosting\Parsedown?

Here is the full 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"
]
}
}

Answer

Looks like you are trying to execute this line of code $Parsedown = new Parsedown(); in a class with namespace UserFrosting.

Either add a use block at the top of your php file, like this: use Parsedown; (this should come after namespace declaration), or type a backslash before the class name when you are using it, like so: $Parsedown = new \Parsedown();. The latter will start looking for this class in a root namespace.

You don't need to add this class to your autoload classmap section of composer.json file. If a package is pulled by composer, the composer will automatically add everything to autoloader after running dump-autoload.