Here comes Laravel 5!

I starting using Laravel around the time that version 4 was released, been on the sidelines waiting for the next version. Came across a cool article today that showcases the new features for Laravel 5 and its got me pumped!

https://laravel-news.com/2015/01/laravel-5/

So many features!

Here's what I'm most excited about..

1. Commands / Eventing

Commands

If you've been keeping up with the Laravel community, the command bus pattern has been gaining some serious attention recently.

Commands help organize domain logic by organizing actions into tasks that your application can perform. That way when something happens (an item purcahsed, user registered) you can send a command to the application for handling.

The emittence of commands is imperative; you are telling the system exactly what to do and it will handle it the same way every time.

More on commands:

http://laravel.com/docs/master/bus

Eventing

Events in Laravel follow the pub/sub pattern in which notices are emitted to the system which then can subscribe to them and respond however they like. In Laravel 5 eventing has been touched up so that instead of string identifiers being used for events ( Event::fire('user.registered', $user)) we can emit actual objects (Event::fire(new UserWasRegistered($user))).

Now events more concrete, you'll get code like:

// The event
class UserWasRegistered extends Event {}

// The handler(s)
class SendRegistrationEmail {

    public function handle(UserWasRegistered $event) {
        // handle it bro!
    }
}

// The listeners (in a ServiceProvider)
$this->listen = [
    UserWasRegistered::class = [
        SendRegistrationEmail::class,
        BuildCustomerProfile::class
    ]
];

I love this! Very clear code, extensible...instead of passing an array of attributes to a handler you can set properties and inject objects to the event constructors. That way data delivered to handlers is always an object with explicit properties.

More on events:

http://mattstauffer.co/blog/laravel-5.0-events-and-handlers

2. Flysystem

I've been using the Flysystem library for a few months now, its in just about every project that I've done.

http://flysystem.thephpleague.com/

Provides a really nice API for the filesystem with adapters for awesome things like:

  • S3
  • (S)FTP
  • Dropbox
  • Rackspace
  • Zip archives

Recently I was tasked with integrating a service that requires frequent FTP uploads to exchange information. This library was invaluable, was able to easily swap out the local implentation for my unit test and keep the FTP adapter for production bound code.

Having this part of Laravel natively will save me some time and effort.

3. dotenv

I saw this guy a bit back, its a great package for loading environment variables from a .env file to $_SERVER, $_ENV, and getenv().

https://github.com/vlucas/phpdotenv

No more hardcoding your environments in the detect function!

Also brings me closer to a goal of writing applications like this:

http://12factor.net/

Perhaps more on that later.

But keeping the configuration in the environment is a pretty cool concept. On deploys you can just inject a .env file to your Laravel 5 application and it will set environment specific / sensitive information for you. In your configs you can just do:

'pgsql' => [
    'username' => $_ENV['database_user'],
    'password' => $_ENV['database_password']
]

Changing the env configurations for an app won't require a full code deploy when using this pattern.

Nifty!

Wrapping it up

So Laravel 5, bring it! I'm pretty pumped to get it up and running on some real projects. I'm in the planning stages of throwing together a few interesting API's for a project I'm working on, definitely gonna give Laravel 5 a spin.

Perhaps I'll post some updates on how that goes.

Anyway, Laravel 5! Lets go!

Further Reading

comments powered by Disqus