升级到Laravel 5后的命名空间问题

时间:2015-09-01 06:24:44

标签: php namespaces laravel-5.1

我正在尝试从4.2更新我们的应用程序到Laravel 5.1。我们将从一开始就进行全面升级。我们在4.2中使用了psr-4命名空间,因此预计不会失败,也无法找到它的来源,一切似乎都很好。我们所有的端点(域名,我们总共有4个)在访问任何路由时都面临同样的问题。

应用程序目录结构

DECLARE @LBrCode AS INT = 2

SELECT 
    COUNT(CASE WHEN A.ActTotBalFcy <= 99.99 THEN A.PrdAcctId END) ,
    SUM(CASE WHEN A.ActTotBalFcy <= 99.99 THEN A.ActTotBalFcy END)
FROM 
    D009022 A
WHERE 
    Substring(A.PrdAcctId, 1, 8) IN ( '20060000', '20060001', '20060002','20060003','20060004', '20060007' )
    AND A.LBrCode = @LBrCode

路线

Console
    Commands
        BackTools
        Consumer
        [Other Endpoints]
Events
Exceptions
Http
    Controllers
        BackTools
        Consumer
        [Other Endpoints]
    Middleware
        BackTools
        Consumer
        [Other Endpoints]
    Requests
    Routes
        BackTools
        Consumer
        [Other Endpoints]
    ViewComposers
        BackTools
        Consumer
        [Other Endpoints]
Jobs
    BackTools
    Consumer
    [Other Endpoints]
Libraries
Listeners
Providers

作曲

Route::group(array(
    'domain' => Config::get('settings.domains.back'),
    'namespace' => 'back\\controllers'
), function () {
    Route::get('login', array('as' => 'auth.back.login', 'uses' => 'AuthController@getBackLogin'));
    Route::get('logout', array('as' => 'auth.back.logout', 'uses' => 'AuthController@getBackLogout'));
    Route::post('login', array('as' => 'auth.back.login', 'uses' => 'AuthController@postBackLogin'));
});

优化后的自动加载类图

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "companyX\\": "app/",
        "back\\composers\\": "app/Http/ViewComposers/BackTools",
        "back\\controllers\\": "app/Http/Controllers/BackTools",
        "back\\jobs\\": "app/Jobs/BackTools",
        "back\\middleware\\": "app/Http/Middleware/BackTools",
        "consumer\\composers\\": "app/Http/ViewComposers/Consumer",
        "consumer\\controllers\\": "app/Http/Controllers/Consumer",
        "consumer\\jobs\\": "app/Jobs/Consumer",
        "consumer\\middleware\\": "app/Http/Middleware/Consumer",          
        "companyX\\commands\\": "app/Console/Commands",
        "companyX\\composers\\": "app/ViewComposers",
        "companyX\\controllers\\": "app/Http/Controllers",
        "companyX\\jobs\\": "app/Jobs",
        "companyX\\libraries\\": "app/Libraries",
        "companyX\\providers\\": "app/Providers"
    }
},

示例错误

'back\\controllers\\AuthController' => $baseDir . '/app/Http/Controllers/BackTools/AuthController.php',
'back\\controllers\\BackToolsController' => $baseDir . '/app/Http/Controllers/BackTools/BackToolsController.php',

1 个答案:

答案 0 :(得分:0)

  • 在提供商下打开RouteServiceProvider
  • 将$ namespace更改为''

如果其他人可以给我一个解释,我会将他的答案标记为最佳。拥有默认命名空间的概念可能会吸引某些人,但对我而言,它破坏了psr-4命名空间最美丽的方面。