将laravel应用程序转换为流明 [英] Converting a laravel application to lumen

查看:57
本文介绍了将laravel应用程序转换为流明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在构建laravel 5.1 API,经过几个月的工作,我意识到我应该一直使用Lumen.

So, I have been building a laravel 5.1 API and after months of work on it it dawned on me that I should have been using Lumen all along.

是否可以将laravel应用转换为流明应用?

Is there a way to convert a laravel app to a lumen app?

推荐答案

Lumen本质上是Laravel的简化版本.该应用程序的结构是相同的,因此就此而言,创建一个新的Lumen应用程序并从您的Laravel应用程序复制app目录应该是安全的.

Lumen is essentially a stripped down version of Laravel. The application structure is the same, so as far as that goes it should be safe to create a new Lumen app and copy the app directory from your Laravel app.

但是,出于性能原因,Lumen并没有开箱即用的Laravel好东西,有些根本就不存在.因此,根据您实施Laravel应用程序的方式,您可能需要更改以下几点才能迁移应用程序:

However, for performance reasons, Lumen does not have all the Laravel goodies working out of the box, and some are not there at all. So depending on how you've implemented you're Laravel app, here's a few things that you might need to change in order to migrate your app:

  • 路由定义将必须迁移,因为流明使用其他路由器
  • 流明默认情况下不使用.env文件,因此您需要如果您想取消对bootstrap/app.php中的行Dotenv::load()的注释,请取消注释
  • 默认情况下也不启用诸如DBMailQueue之类的外观.您可以通过取消注释bootstrap/app.php中的$app->withFacades()来启用它们.但是,即使您确实启用了它们,您也只能您在Laravel中获得的部分外墙
  • 需要通过在bootstrap/app.php
  • 中取消注释$app->withEloquent()来启用口才
  • Route definitions will have to be migrated because Lumen uses a different router
  • Lumen does not use the .env file by default, so you need to uncomment the line Dotenv::load() in bootstrap/app.php if you want it to work
  • Facades such as DB, Mail, Queue are also not enabled by default. You can enable them by uncommenting $app->withFacades() in bootstrap/app.php. However, even if you do enable them you only get a portion of the facades that you get in Laravel
  • Eloquent needs to be enabled by uncommenting $app->withEloquent() in bootstrap/app.php

我可能没有涵盖所有内容,但这是为了让您对应该注意的事情有个想法.可以启用所有这些功能,但是Lumen带来的性能优势主要是因为禁用了这些功能以消除这些开销,因此,请尝试尽可能地修改您的应用程序,以利用默认情况下Lumen提供的功能.

I've probably not covered everything, but this is to offer an idea on what you should be looking out for. All those things can be enabled, but the performance benefits Lumen brings are mostly because those things are disabled to get rid of that overhead, so try to modify your application wherever possible to make use of what Lumen offers by default.

这篇关于将laravel应用程序转换为流明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆