lumen

16
+ Lumen The stunningly fast micro-framework by Laravel. By: Joshua Copeland @PsycodeDotOrg

Upload: joshua-copeland

Post on 12-Aug-2015

135 views

Category:

Software


9 download

TRANSCRIPT

Page 1: Lumen

+Lumen

The stunningly fast micro-framework by Laravel.

By: Joshua Copeland

@PsycodeDotOrg

Page 2: Lumen

+

Joshua Copeland

[email protected]

- Father, Husband, Code Craftsman, and self proclaimed Computer.

@PsycodeDotOrg

LV PHP UG

Organizer

Lead Developer @

Selling Source

Lover of all things tech

Proud Father of 2

Page 3: Lumen

+Server Requirements

The Lumen framework has a few system requirements:

PHP >= 5.4 Mcrypt PHP Extension OpenSSL PHP Extension Mbstring PHP Extension Tokenizer PHP Extension

Page 4: Lumen

+Homestead 5.0

Download/Install Vagrant & Virtualbox (or VMWare) vagrant box add laravel/homestead git clone https://github.com/laravel/homestead.git ~/Homestead

bash ~/Homestead/init.sh cd ~/Homestead && ./homestead edit

#Verify settings (ssh key, blackfire, etc.)#Edits the ~/.homestead/Homestead.yaml config file

composer install #Your native machine needs php/composer to run bin from host

vagrant up #Expect lots of output.

#Seeing some red text might not be an actual error. vagrant ssh

#Its Alive!

Page 5: Lumen

+Homestead 5.0

Included Software Ubuntu 14.04 PHP 5.6 HHVM Nginx MySQL Postgres Node (With Bower, Grunt, and Gulp) Redis Memcached Beanstalkd Laravel Envoy Blackfire Profiler

Ports The following ports are forwarded to

your Homestead environment: SSH: 2222 → Forwards To 22 HTTP: 8000 → Forwards To 80 HTTPS: 44300 → Forwards To 443 MySQL: 33060 → Forwards To 3306 Postgres: 54320 → Forwards To 5432

Adding Additional PortsIf you wish, you may forward additional ports to the Vagrant box, as well as specify their protocol:

ports: - send: 93000 to: 9300 - send: 7777 to: 777 protocol: udp

Page 6: Lumen

+Lumen Installation

Install Composer Lumen utilizes Composer to manage its dependencies. So, before using Lumen, you

will need to make sure you have Composer installed on your machine.

Via Lumen Installer First, download the Lumen installer using Composer.

composer global require "laravel/lumen-installer=~1.0" Make sure to place the ~/.composer/vendor/bin directory in your PATH so the lumen

executable can be located by your system. Once installed, the simple lumen new command will create a fresh Lumen installation

in the directory you specify. For instance, lumen new service would create a directory named service containing a fresh Lumen installation with all dependencies installed. This method of installation is much faster than installing via Composer: lumen new service

Via Composer Create-Project You may also install Lumen by issuing the Composer create-project command in your

terminal: composer create-project laravel/lumen --prefer-dist

Page 7: Lumen

+Pretty URLs

Apache The framework ships with a

public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Lumen application, be sure to enable the mod_rewrite module.

If the .htaccess file that ships with Lumen does not work with your Apache installation, try this one:

location / { try_files $uri $uri/ /index.php?$query_string;}

Nginx On Nginx, the following

directive in your site configuration will allow "pretty" URLs:

Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]

When using Homestead, pretty URLs will be configured automatically.

Page 8: Lumen

+Directory Structure

app/ All your application code goes here. Console commands, service providers, routes,

controllers, middleware, exceptions, and jobs.

bootstrap/app.php Create the app used as an “IoC” application container & router. Register container bindings, service providers, and middleware.

database/

public/ The public web facing files (index.php)

resources/

storage/

tests/

vendor/

Page 9: Lumen

+Configuration

Lumen needs almost no other configuration out of the box. You are free to get started developing!

You may also want to configure a few additional components of Lumen: Cache Database Queue Session

Permissions Lumen may require some permissions to be configured: folders within storage

directory need to be writable.

Page 10: Lumen

+Configuration

Copy .env.example to .env in root of project.

The example config: APP_ENV=localAPP_DEBUG=trueAPP_KEY=Change This!!!

APP_LOCALE=enAPP_FALLBACK_LOCALE=en

DB_CONNECTION=mysqlDB_HOST=localhostDB_PORT=3306DB_DATABASE=homesteadDB_USERNAME=homesteadDB_PASSWORD=secret

CACHE_DRIVER=memcachedSESSION_DRIVER=memcachedQUEUE_DRIVER=database

Page 11: Lumen

+HTTP Routing

$app->post('foo/bar', function() { return 'Hello World';});

$app->patch('foo/bar', function() { //});

$app->put('foo/bar', function() { //});

$app->delete('foo/bar', function() { //});

$app->get('user/{id}', function($id) { return 'User '.$id;});

$app->group(['prefix' => 'accounts/{account_id}'], function($app){ $app->get('detail', function($account_id) { // accounts/1234/details });});

Page 12: Lumen

+HTTP Middleware

HTTP middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Lumen includes a middleware that verifies the CSRF token of your application.

Of course, middleware can be written to perform a variety of tasks besides CSRF validation. A CORS middleware might be responsible for adding the proper headers to all responses leaving your application. A logging middleware might log all incoming requests to your application.

All middleware are typically located in the app/Http/Middleware directory.

To create a new middleware, simply create a class with a handle method like the following:

public function handle($request, $next){ // Do stuff here, then continue request handling return $next($request);}

Page 13: Lumen

+HTTP Controllers

<?php namespace App\Http\Controllers;

use App\User;use App\Http\Controllers\Controller;

class UserController extends Controller {

/** * Show the profile for the given user. * * @param int $id * @return Response */ public function showProfile($id) { return view('user.profile', ['user' => User::findOrFail($id)]); }

}

// We can route to the controller action like so$app->get('user/{id}', 'App\Http\Controllers\UserController@showProfile');

Page 14: Lumen

+Views

<!-- View stored in resources/views/greeting.php -->

<!doctype html><html> <head> <title>Welcome!</title> </head> <body> <h1>Hello, <?php echo $name; ?></h1> </body></html>The view may be returned to the browser like so:

$app->get('/', function() { return view('greeting', ['name' => 'James']);});

Page 15: Lumen

+Other features

• Core Features• Cache• Database• Encryption• Errors & Logging• Events• Helpers• Queues• Unit Testing• Validation

• Full-Stack Features• Authentication• Filesystem / Cloud Storage• Hashing• Mail• Pagination• Session• Templates

http://lumen.laravel.com/docs

Page 16: Lumen

+Thank you!

Joshua Copeland

[email protected]

@PsycodeDotOrg

http://spkr8.com/t/59581