Introduction to Lumen

Lumen is a brand spanking new PHP micro-framework developed by the writer of the Laravel framework, Taylor Otwell. Do not stress, though--Lumen isn't meant to replace Laravel. Actually, the thought behind Lumen is the fact that it complements your present or future Laravel programs.

In this informative article I'd like to go over what is different in Lumen, when we should use Lumen, and how we can use Lumen. I will also describe how we can take our Lumen program and simply migrate it to a complete-heap Laravel program. There will not be a whole lot of code, as Lumen is substantially the same as Laravel. Let us get started.

This may most probably be the first question that many of you'll be inquiring. In fact, not a whole lot is really "new" with Lumen aside from the adhesive. Lumen still uses most of the Illuminate elements which make up the Laravel framework (there are just a couple missing). Think of it as a slimmed down Laravel setup. ! 

There are a couple of tradeoffs here. FastRoute is an extremely quick execution, but it is not as feature-packed as the Symfony router. In case you would like to use sub domain routing then youare going to need to stay with a Laravel install which uses the Symfony router. ! 

The other tradeoff worth saying is that for finer control over layout of particular parts you will have to change configuration files within the seller/laravel/lumen-framework directory. Nearly all the setup may be carried out through the .env files, but some lesser configured matters are not directly configurable.

The solution here will depend, but likely not. In the event you are developing or have developed an application on Laravel (4 or 5), then you almost certainly will not need to change to Lumen right this very minute. While Lumen is effective at creating a full blown web application, it's better suited to the smaller, decoupled services and APIs. !

Let us say you are assembling a big web shop program. So you proceed and install Laravel and get to work on a monolithic program. Now, there is nothing wrong with this particular strategy, and also you might find it works good for you. If so, carry on. In the event you see you are becoming overwhelmed with the sophistication, or things appear to be getting a little out of hand, then you definitely might want to split it up into some smaller, more manageable bits. !

You'd use Lumen to make different programs for every decoupled service. For our store we might split off the bill, email notifications, sending, and tracking to divide programs. All these programs would be a self contained Lumen install and every program would just do a particular job. 

To empower our primary program to speak with our decoupled services, we had use queues as well as a service like Amazon SQS. We can use queues to easily queue up jobs, and every service would listen for its specific occupations and process them as they are queued. The advantage to this strategy is the fact that every service may be scaled and installed independently of one another. 

You can also use Lumen to construct an API which may even be used up by your primary program together with the aid of an HTTP client such as Guzzle. This decoupling lets you scale and optimize the business side of your program without interfering with the rest. !

By now you ought to have an excellent thought as to whether or not using Lumen is the correct measure for you. Installing Lumen is as easy as installing Laravel: a straightforward composer create-job command, or you'll be able to install the lumen command to generate new jobs. We'll only use Composer to snatch a fresh install.

Composer will pull down all of the dependencies. It's possible for you to use Artisan to immediately serve up the program to have a look, or you also may set up a Virtual Host or Homestead website. Either way, when you reach the trail to your Lumen setup you will see the glistening splash page telling you that Lumen is better to go.

The remaining bootstrapping that you just will wish to be alert to is in the bootstrap/program.php file. In the event you are using the .env settings mentioned previously then you will need to remark Dotenv::load(__DIR__.'/../');. Scrolling by means of this file you will see several remarked lines which you might need to remark. There is the loading of facades, Eloquent, some middlewares, as well as the enrollment of other providers.

You might be constructing your Lumen program and everything is going totally good, until one fateful day when you realise you need something which just the total-pack Laravel framework offers. Do not stress, however, as it is an incredibly painless upgrade. Here are the steps to follow:

That should be the majority of the thing you must reproduce to be able to migrate your Lumen program to Laravel. Obviously, this works both ways, in order to quickly migrate a Laravel program to Lumen in the event you understand you do not want everything the total-stack framework offers.

To wrap this up, I simply wish to point out that I am recommending the use of Lumen mainly for decoupled services and APIs, which is its planned use. That is not to imply you can not construct an entire program on Lumen, because you can. Should you decide to do it, that is good. There are not any rules carved in a stone tablet telling you what you can and can not use for your jobs. At the conclusion of the day the choice is left up to you personally. Consider your choices, organize your job, make a decision as to what you will desire, consult your team, and make your final decision.



Posted on May 08, 2015 at 09:00 PM