Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lumen

1,009 views

Published on

A talk about the new PHP micro framework based on Laravel called Lumen.

Published in: Software
  • Be the first to comment

Lumen

  1. 1. + Lumen The stunningly fast micro-framework by Laravel. By: Joshua Copeland @PsycodeDotOrg
  2. 2. + Joshua Copeland Josh@Psycode.org - 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
  3. 3. + 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
  4. 4. + 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!
  5. 5. + 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 Ports If 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
  6. 6. + 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
  7. 7. + 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 +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] When using Homestead, pretty URLs will be configured automatically.
  8. 8. + 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/
  9. 9. + 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.
  10. 10. + Configuration  Copy .env.example to .env in root of project.  The example config: APP_ENV=local APP_DEBUG=true APP_KEY=Change This!!! APP_LOCALE=en APP_FALLBACK_LOCALE=en DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret CACHE_DRIVER=memcached SESSION_DRIVER=memcached QUEUE_DRIVER=database
  11. 11. + 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 }); });
  12. 12. + 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); }
  13. 13. + HTTP Controllers <?php namespace AppHttpControllers; use AppUser; use AppHttpControllersController; 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}', 'AppHttpControllersUserController@showProfile');
  14. 14. + 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']); });
  15. 15. + 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
  16. 16. + Thank you!

×