Silex 找不到控制器 Class

Silex can't find Controller Class

项目目录结构

/composer.json
/web/index.php
/app/controller/IndexController.php 

composer.json

{
  "require" : {
    "silex/silex": "*"
  },
  "autoload": {
    "psr-0": {
            "": "./"
        }
  }
}

index.php

<?php

require_once __DIR__.'/../vendor/autoload.php';

use Silex\Application;

$app = new Application();
$app['debug'] = true;

$app->get('/', 'App\Controller\IndexController::getIndex');

$app->run();

IndexController.php

<?php

namespace App\Controller;

use Silex\Application;

class IndexController
{
    public function getIndex(Application $app)
    {
        return "You got the index, congrats!";
    }
}

每当我

cd web/
php -S localhost:8080
curl http://localhost:8080

从项目根目录我得到以下异常

InvalidArgumentException in ControllerResolver.php line 153:
Class "App\Controller\IndexController" does not exist.
in ControllerResolver.php line 153
at ControllerResolver->createController('App\Controller\IndexController::getIndex') in ControllerResolver.php line 80
at ControllerResolver->getController(object(Request)) in HttpKernel.php line 135
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 581
at Application->handle(object(Request)) in Application.php line 558
at Application->run() in index.php line 12

这对我来说毫无意义。该程序实际上 运行 在我的 MacBook 上本地运行良好,但是当我将它部署到我的 Ubuntu VPS 时,即使代码在两个环境中都是 运行,我也会收到上述异常是相同的。为什么 Silex 找不到我的控制器?

这是一个大写问题。我的 macbook 有一个不区分大小写的文件系统,而我的 Linux VPS 有一个区分大小写的文件系统,所以在部署到 VPS 时,我必须将项目中的目录大写,这样 Silex 才能正确解析控制器。

试试这个

"autoload" : {
    "psr-4" : {
        "App\Controller\" : "app/controller/"
    }
}

就我而言,我错过了 use Symfony\Component\HttpFoundation\Request; 行。

来自this post

Check that your controller has this:

use Silex\Application;

use Symfony\Component\HttpFoundation\Request;