Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class does not comply with psr-4 autoloading standard. Skipping [duplicate]

I try to use composer autoload but I get this error

composer.json

{
    "autoload":{
        "psr-4":{
            "App\\":"app/"
        },
        "files": ["app/functions/helper.php"]
    },
    "require": {
        "vlucas/phpdotenv": "^2.4",
        "altorouter/altorouter": "^1.2",
        "philo/laravel-blade": "^3.1"
    },
    "config":{
        "optimize-autoloader":true
    }
}

my terminal output

Generating optimized autoload files
Class App\Controllers\BaseController located in D:/php/Xamp/htdocs/MVC_PHP/app\controllers\BaseController.php does not comply with psr-4 autoloading standard. Skipping.
Class App\Controllers\IndexControllers located in D:/php/Xamp/htdocs/MVC_PHP/app\controllers\IndexControllers.php does not comply with psr-4 autoloading standard. Skipping.
Class App\RoutingDispatcher located in D:/php/Xamp/htdocs/MVC_PHP/app\routing\RoutingDispatcher.php does not comply with psr-4 autoloading standard. Skipping.
Generated optimized autoload files containing 508 classes
like image 737
Ahmed Balti Avatar asked Nov 27 '20 13:11

Ahmed Balti


People also ask

What is PSR 4 autoloading standard laravel?

This PSR describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification.

What is composer dump autoload?

composer dump-autoload. php artisan dump-autoload. It regenerates the list of all the classes that need to be included in the project (autoload_classmap. php). It will 'recompile' loads of files creating the huge bootstrap/compiled.php.


1 Answers

The PSR-4 standard requires your files and directories to be case sensitive and the corresponding classes and namespaces to be in PascalCase.

For a App\Controllers\BaseController class, the file should be located in:

app/Controllers/BaseController.php

Notice the uppercase C

2nd error: For any namespace after the top level namespace, there must be a directory with the same name.
You have a App\RoutingDispatcher class that should be placed as app/RoutingDispatcher.php but the app/routing/RoutingDispatcher.php file would correspond to a App\Routing\RoutingDispatcher class.
You must change the namespace of that class or move the file.

If you change its namespace, be sure to rename the app/routing directory with a leading uppercase letter.

like image 76
AymDev Avatar answered Oct 09 '22 14:10

AymDev