[英]How can I bootstrap a Laravel application from within a Laravel application?
我正在尝试构建一个概念证明来解决以下问题:我需要将 Kohana 应用程序重构为 Laraval,但我们不断添加新功能并开发应用程序。 所以 Kohana 和 Laravel 代码库必须协同工作一段时间。
为了验证概念,我采用了两个 Laravel 应用程序,其中一个模拟了旧的 Kohana 应用程序。
我想到的一个解决方案是在 Laravel 应用程序中创建一个中间件或服务提供者,以检查该路由是否可以在此 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;
}
}
有没有人知道出了什么问题,或者对另一种解决方案有建议?
问题是由去命名空间引起的。
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
应该
$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
这也适用于
$request = Illuminate\Http\Request::capture()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.