如何从Laravel应用程序中引导Laravel应用程序?

问题描述 投票:0回答:1

我正在尝试建立概念证明来解决以下问题:我需要将Kohana应用程序重构为Laraval,但我们一直在添加新功能并开发该应用程序。因此Kohana和Laravel代码库必须一起工作一段时间。

[为证明概念,我采用了两个Laravel应用程序,其中一个模拟了旧的Kohana应用程序。

我想到的解决方案是在Laravel应用程序中创建一个中间件或服务提供商,以检查该Laravel中的路由是否可以解决。如果无法解析路由,则应引导另一个应用程序执行请求。

当我尝试从第一个中间件类中引导第二个Laravel时,出现以下错误:

Target class [App\Http\Middleware\Illuminate\Contracts\Http\Kernel] does not exist.

执行以下行:

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

中间件处理功能:

public function handle($request, Closure $next)
{
    $routes = Route::getRoutes();
    try {
        //route exists
        $routes->match($request);

        return $next($request);
    }
    catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e){
        //route doesn't exist

        // define('LARAVEL_START', microtime(true));
        require_once env('LARAVEL_FILE_PATH').'/vendor/autoload.php';

        $app = require_once env('LARAVEL_FILE_PATH').'/bootstrap/app.php';

        $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

        $response = $kernel->handle(
            $request = Illuminate\Http\Request::capture()
        );

        $response->send();

        $kernel->terminate($request, $response);

        exit;
    }
}

是否有人知道出了什么问题或对其他解决方案有建议?

php laravel refactoring bootstrapping
1个回答
0
投票

该问题是由于取消命名空间引起的。

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

应该是

$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);

也是如此

 $request = Illuminate\Http\Request::capture()
© www.soinside.com 2019 - 2024. All rights reserved.