I've got a situation using composer to load a class in a Silex app.
This class is located at:
src/custom/UserProvider.php
In my composer.json, I've added this lines:
"autoload": {
"psr-0": {
"CustomNamespace": "src/custom/"
}
}
Inside my UserProvider.php file, I've got:
namespace CustomNamespace;
When I ran composer update in console, this line was added to the /vendor/composer/autoload_namespaces.php
'CustomNamespace' => $baseDir . '/src/custom/',
But, when I try to use the class:
new CustomNamespace\UserProvider();
I got this error:
Fatal error: Class 'CustomNamespace\UserProvider' not found in /home/ubuntu/www/project/web/index.php on line 27
Does anyone knows what's going on? Thanks!
The problem is exactly what @Maerlyn said in his comment.
Everthing works fine when I moved my file to src/custom/CustomNamespace/UserProvider.php
I'll just add a note here if someone comes across my issue, which displayed itself the same as this question, but had to do with case sensitivity.
I moved my site from OS X (not case sensitive) to Ubuntu (case sensitive), which complained that the class did not exist. The file was named myclass.php, and when I renamed it to MyClass.php it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With