Composer Class Not Found Even If It Exists
I'm developing a Laravel package but I have a problem with composer autoloading.
My package has 2 folders under src
folder. One of them is named Laravel
and the other one is Telegram
. Here is the package structure:
./packages
.../typhoon
...../src
......./Laravel
........./Providers
............LumenServiceProvider.php
............LaravelServiceProvider.php
......./Telegram
..........Api.php
.....composer.json
This package is developed under SaliBhdr/Typhoon
namespace.
I have added the packages/typhoon/src
directory in Laravel's composer file like so:
"autoload": {
"psr-4": {
"App\\": "app/",
"SaliBhdr\\Typhoon\\" : "packages/typhoon/src/"
}
},
And add the src/
address in package composer.json file like so:
"autoload": {
"psr-4": {
"SaliBhdr\\Typhoon\\": "src/"
}
},
Here is the strange behavior begins. When I execute the php artisan serve
command Laravel throws an error that says :
Class 'Salibhdr\Typhoon\Laravel\Providers\LumenServiceProvider' not found
And if I check if the class exists with class_exists('Salibhdr\Typhoon\Laravel\Providers\LumenServiceProvider')
function it returns false
. But if I check if Salibhdr\Typhoon\Telegram\Api
exists it returns true
.
I checked the autoload_classmap
file and notice that the composer includes all the classes under Telegram
subfolder but not Laravel
subfolder.
Why composer acts weird like this? why did it include one subfolder and not the other? It is something that I do every day and never seen anything like this.
I desperately need help. Any help would be appreciated
Answer
You are trying to initialize Salibhdr\Typhoon\Laravel\Providers\LumenServiceProvider
but in your composer it's "SaliBhdr\\Typhoon\\": "src/"
.
Notice the capital B
in your composer. PHP classes are case sensitive so you have to make sure it's either both lowercase or both uppercase.
Also make sure to run composer dumpautoload
if you modify composer.json
.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?