超薄3中间件和psr-4作曲家自动加载器:找不到类

composer.json:

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},

src/Auth/RequestMethodPathRule.php:

namespace App\Auth;
class RequestMethodPathRule implements  \Slim\Middleware\HttpBasicAuthentication\RuleInterface 
{ 
...

src/middleware.php

$app->add(new \Slim\Middleware\HttpBasicAuthentication([
    "rules" => [new App\Auth\RequestMethodPathRule(

This results in

Class 'App\Auth\RequestMethodPathRule' not found.

Including all of the code in RequestMethodPathRule.php in the file middleware.php works fine.

More strangely, along with the 500 error, the browser displays the source code of RequestMethodPathRule.php!

EDIT: Oh my, I had a shorttag on the class file (<? instead of <?php) so php treated it as text. Habits are hard to quit.

More strangely, along with the 500 error, the browser displays the source code of RequestMethodPathRule.php!

That's mean that composer correctly include the file, but no class is found because the code isn't interpret by php. In this case, since the short tags aren't a usually enabled, you just need to replace them with the <?php tag instead.