LumenとLaravelの違い

LumenとLaravelの違いがどの程度なのか知りたいと思い、以下の3つの視点から違いを調べて見ました。

  • ドキュメント
  • ディレクトリ構成
  • artisan コマンド

Lumenの概要を知りたい方は、「マイクロフレームワーク LUMEN 登場」をご覧ください。

※ この記事は Laravel 5.0 と Lumen 5.0 を比較した時のものです。


ドキュメントにみる違い

◯がドキュメントの目次があるもの、✕はないものです。

目次 Laravel Lumen
# The Basics
Routing
Middleware
Controllers
Requests
Responses
Views
# Architecture Foundations
Service Providers
Service Container
Facades ◯※1
# Services
Authentication
Billing
Cache
Collections ◯※1
Command Bus ✕※2
Core Extension
Elixir
Encryption
Envoy
Errors & Logging
Events
Filesystem / Cloud Storage
Hashing
Helpers
Localization ◯※1
Mail
Package Development
Pagination
Queues
Session
Templates
Unit Testing
Validation
# Database
Basic Usage
Query Builder
Eloquent ORM
Schema Builder
Migrations & Seeding
Redis

※1 … Lumenのドキュメントには無いが、使えるっぽい物。
※2 … Command Bus は、Queueと統合された?

目立ったところでは、以下の機能が Lumen には無いようです。

  • Command Bus(Queueと統合?)
  • Elixir

思いのほか、Laravel の大部分の機能が使えることがわかります。


ディレクトリ構成にみる違い

# Laravelのディレクトリ構成

[x] が付いているものが、Lumenで無くなったディレクトリです。

Laravel
├── app
│   ├── Commands            [x]
│   ├── Console
│   │   └── Commands
│   ├── Events              [x]
│   ├── Exceptions
│   ├── Handlers            [x]
│   │   ├── Commands       [x]
│   │   └── Events         [x]
│   ├── Http
│   │   ├── Controllers
│   │   │   └── Auth      [x]
│   │   ├── Middleware
│   │   └── Requests       [x]
│   ├── Providers
│   └── Services            [x]
├── bootstrap
├── config                   [x]
├── database
│   ├── migrations
│   └── seeds
├── public
│   ├── css                 [x]
│   └── fonts               [x]
├── resources
│   ├── assets              [x]
│   │   └── less           [x]
│   │       └── bootstrap  [x]
│   │           └── mixins [x]
│   ├── lang
│   │   └── en
│   └── views
│       ├── auth            [x]
│       ├── emails          [x]
│       └── errors          [x]
├── storage
│   ├── app
│   ├── framework
│   │   ├── cache
│   │   ├── sessions
│   │   └── views
│   └── logs
└── tests

最も大きな違いは config ディレクトリが削除されたことです。composerとサービスプロバイダーを使ったパッケージの追加は意図されていないようです。代わりに必要な設定は bootstrap/app.php 内や .env で行うようになっています。これは、アプリのスピードを上げる為に、柔軟性、拡張性を捨てて、起動プロセスをチューニングした結果だと思われます。

その他には、コマンドバス、イベント、認証、アセット、ビューのデフォルトファイル等が削除されています。

# Lumenのディレクトリ構成

[o] が付いているものが、Lumenで追加されたディレクトリです。

Lumen
├── app
│   ├── Console
│   │   └── Commands
│   ├── Exceptions
│   ├── Http
│   │   ├── Controllers
│   │   └── Middleware
│   ├── Jobs                  [o]
│   └── Providers
├── bootstrap
├── database
│   ├── migrations
│   └── seeds
├── public
├── resources
│   ├── lang
│   │   ├── en
│   │   └── ja
│   └── views
├── storage
│   ├── app
│   ├── framework
│   │   ├── cache
│   │   ├── sessions
│   │   └── views
│   └── logs
└── tests

app/Jobsディレクトリは app/Commandsディレクトリの名前が変更になったものと思われます。このディレクトリ名変更は Laravel 5.1 でも予定されています。


artisan コマンドにみる違い

[o] が付いている物が Lumenでも使えるコマンドです。

# Available commands:
  [x] clear-compiled       Remove the compiled class file
  [x] down                 Put the application into maintenance mode
  [x] env                  Display the current framework environment
  [x] fresh                Remove the scaffolding included with the framework
  [o] help                 Displays help for a command
  [x] inspire              Display an inspiring quote
  [o] list                 Lists commands
  [o] migrate              Run the database migrations
  [x] optimize             Optimize the framework for better performance
  [o] serve                Serve the application on the PHP development server
  [x] tinker               Interact with your application
  [x] up                   Bring the application out of maintenance mode

# app
  [x] app:name             Set the application namespace

# auth
  [x] auth:clear-resets    Flush expired password reset tokens

# cache
  [o] cache:clear          Flush the application cache
  [o] cache:table          Create a migration for the cache database table

# config
  [x] config:cache         Create a cache file for faster configuration loading
  [x] config:clear         Remove the configuration cache file

# db
  [o] db:seed              Seed the database with records

# event
  [x] event:generate       Generate the missing events and handlers based on registration

# handler
  [x] handler:command      Create a new command handler class
  [x] handler:event        Create a new event handler class

# key
  [x] key:generate         Set the application key

# make
  [x] make:command         Create a new command class
  [x] make:console         Create a new Artisan command
  [x] make:controller      Create a new resource controller class
  [x] make:event           Create a new event class
  [x] make:middleware      Create a new middleware class
  [o] make:migration       Create a new migration file
  [x] make:model           Create a new Eloquent model class
  [x] make:provider        Create a new service provider class
  [x] make:request         Create a new form request class

# migrate
  [o] migrate:install      Create the migration repository
  [o] migrate:refresh      Reset and re-run all migrations
  [o] migrate:reset        Rollback all database migrations
  [o] migrate:rollback     Rollback the last database migration
  [o] migrate:status       Show a list of migrations up/down

# queue
  [o] queue:failed         List all of the failed queue jobs
  [o] queue:failed-table   Create a migration for the failed queue jobs database table
  [o] queue:flush          Flush all of the failed queue jobs
  [o] queue:forget         Delete a failed queue job
  [o] queue:listen         Listen to a given queue
  [o] queue:restart        Restart queue worker daemons after their current job
  [o] queue:retry          Retry a failed queue job
  [o] queue:subscribe      Subscribe a URL to an Iron.io push queue
  [o] queue:table          Create a migration for the queue jobs database table
  [o] queue:work           Process the next job on a queue

# route
  [x] route:cache          Create a route cache file for faster route registration
  [x] route:clear          Remove the route cache file
  [x] route:list           List all registered routes

# schedule
  [o] schedule:run         Run the scheduled commands

# session
  [x] session:table        Create a migration for the session database table

# vendor
  [x] vendor:publish       Publish any publishable assets from vendor packages

目立ったところでは…

  • reoute:list が使えない。
  • make系のコマンドが migration以外は全て使えません。
  • migrate, queue系は全て使えます。
  • tinkerが使えない。

make系のコマンドを切り捨てているところから、Lumenは機能豊富なアプリを作成することは割りきって捨てている模様です。


まとめ

まだ、Lumenを使い込んだ訳ではありませんが、上記の調査から Lumenがどの様な物か大分見えてきました。

  • Laravelの大部分の機能が使える
  • アプリのスピードを上げる為に、柔軟性、拡張性を捨てて、起動プロセスをチューニングした
  • 機能豊富なアプリを作成することは割りきって捨てた

# Lumen とは

Lumen とは、Laravel のパワフルで便利な機能はそのままに、しかし、 柔軟性と拡張性を捨て、パフォーマンスを最優先にチューニング・再構成した Laravel です。

# マイクロとか軽量とか

Lumenにおける「マイクロ、軽量」といった言葉は、「動作が軽く、速い」ということです。フレームワーク全体の「サイズが小さい、コンパクト」といったことではありません。「機能が少なく、簡単で、覚えやすい」といったことでもありません。

# Lumen のイメージ

イメージ Laravel Lumen
間違い 全部盛りラーメン
トッピングてんこ盛りで超リッチだよ。
ラーメン
トッピングして自分好みにできるよ。
正しい お店のおすすめ そば
ある程度トッピング済みだよ。
追加トッピングして自分好みにできるよ。
お店のおすすめ わんこそば
ある程度トッピング済みだよ。
追加トッピングはできないよ。
とにかく速く、多く食べれるよ。

※ 正確には、Lumenは機能拡張できます。コンポーザーでパッケージ追加は出来ますし、サービスプロバイダーも bootstrap/app.php で追加できます。出来ないというよりは、あまり意図いないという感じです。この記事では、あえて特徴を強調して記述しています。

# Lumenの使い所

  • 大量のトラフィックを裁く必要のあるもの
  • APIサーバ
  • ちょっとした物を作る時(Lumenにパッケージを追加しなくて済む範囲)

元々 Laravel で作っていたアプリの一部の機能を Lumen アプリに切り出すといったこともあるでしょう。

画面付きのアプリを開発するなら、Laravelを選択するべきかと思います。
パッケージ追加の必要性がある場合も、Laravelを選択するべきです。

コメントを残す