Say hello to Lumen!

Today (14-04-2015) Taylor Otwell just released Lumen. Lumen is a "micro-framework" built on top of Laravel's components, and is the official micro-framework of Laravel. Lumen is built for speed, and is one of the fastest PHP micro-frameworks available - even significantly faster than similar frameworks such as Silex.

Read a whole article about the release here.

Lets take that baby for a spin!

So lets install the installer and create a verry small application. Lets start by installing the installer globaly. Open up your terminal and paste in the following

composer global require "laravel/lumen-installer=~1.0"  

make sure you got ~/.composer/vendor/bin in your path export. You can do this by adding

Now run lumen new acme and BAM we got our new lumen application ready to run!
Lets see how the directory looks:

Lumen Directory structure

It pretty much looks allot like you are used to with Laravel. The difference we can see right away is that comparing to Laravel we are missing the following:

  • database/
  • resources/
  • gulpfile.js
  • package.json
  • phpspec.yml
  • phpunit.xml

app/

So lets open up the /app folder and see what is still there.
What we are missing are the following directories:

  • Handlers
  • Commands
  • Events
  • Services

And offcourse the Commands/ folder what looks like the new Jobs directory is there! that is also comming to Laravel 5.1 as taylor mentioned a few times in the podcasts he was on.

bootstrap/

Here there did not change a whole lot the only file still in here is the app.html"public">public/

All the garbage is out of here, there is only one single file and that is index.html"storageandtests">storage/ and tests/

There folders are exactly the same as what it is in the Laravel app so we can skip these!

What is in the composer.json file?

Well the following

{
    "name": "laravel/lumen",
    "description": "The Laravel Lumen Framework.",
    "keywords": ["framework", "laravel", "lumen"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/lumen-framework": "5.0.*",
        "vlucas/phpdotenv": "~1.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

As you can see here not a very big of a difference we can see that phpspec is not included anymore by default and also that the classmap for the [database/ folder (https://github.com/laravel/laravel/blob/master/composer.json#L15) is missing but that is obvious since the folder is not in by default anymore.

And well those are the changes to take in accound right now.

How is the artisan looking?

So lets do a quick php artisan to checkout what is there!

It looks like alot of default commands are gone there and is only concerned with caching and queing the application. But also the awesome Eloquent migrations php artisan migrate awesome!

How is the welcome screen?

So as we could see in the previous How is the artisan looking section we still have the ability to use the php artisan serve command so lets spin the baby up! And we get:

a even cleaner page than as Laravel itself what is only a logo name and quote.

So now lets add our own route to test out how we would return a string. Open up app/Http/routes.html'test', function(){ return 'My awesome Lumen post.'; });

Goto https://localhost:8000/test and we should see

My awesome Lumen post. And jup! it just works. now lets try to return an array as in Laravel the framework will translate the array to a json response. Lets change the previous /test get request to return a multi nested array:

$app->get('test', function(){
    return [
        'acme' => [
            'foo','bar'
        ],
        'meh' => [
            'sheep', 'dog'
        ]
    ];
});

Lets hit refresh on https://localhost:8000/test and BAM we have a nice json response waiting there for us:

So, Lets call it a day

So there are many other options to explore here that are included by default like:

  • middlewares
  • Jobs
  • Console

Those will work almost exactly the same as in a Laravel application however we will take a look what we could do with it anyhow.