LoginSignup
15
4

More than 3 years have passed since last update.

Laminasことはじめ

Last updated at Posted at 2020-07-26

Laminasをとりあえずローカルで動かしてみようという記事です。
おや?Laminasをご存じない?
PHPといえばZend、そう、ZendFrameworkがLinux Fundationに移行されて後続的にOSSとして開発されているのがLaminasです。

Laminasにもいくつかパッケージがあり、

  • Component and MVC
  • Mezzio(ZendExpressiveの後続)
  • API Tools

今回はMVCのSkeletonをローカルで動かすまでをやってみます。
ありがたいことにこんな素敵なリポジトリがあり、READMEを追って作業するだけであっという間に立ち上がります。
https://github.com/laminas/laminas-mvc-skeleton

導入

ちなみにMacOS環境でローカルにPHP7.4,Composerを導入済みです。

適当なディレクトリを作成してcomposerを実行するだけですね。

$ mkdir laminas
$ composer create-project -sdev laminas/laminas-mvc-skeleton laminas

実行するとコンソールで対話式に色々聞かれます。
適当に選んでいきます。

Do you want a minimal install (no optional packages)? Y/n
N

Would you like to install the developer toolbar? y/N
Y

Would you like to install caching support? y/N
Y

Would you like to install database support (installs laminas-db)? y/N
Y

Would you like to install forms support? y/N
N

Would you like to install JSON de/serialization support? y/N
Y

Would you like to install logging support? y/N
Y

Would you like to install MVC-based console support? (We recommend migrating to zf-console, symfony/console, or Aura.CLI) y/N
Y

Would you like to install i18n support? y/N
N

Would you like to install the official MVC plugins, including PRG support, identity, and flash messages? y/N
Y

Would you like to use the PSR-7 middleware dispatcher? y/N
Y

Would you like to install sessions support? y/N
Y

Would you like to install MVC testing tools for testing support? y/N
Y

Would you like to install the laminas-di for laminas-servicemanager? y/N
Y

一通り必要なパッケージの有無を求められました。
続いて設定ファイルに関して聞かれます。

  Please select which config file you wish to inject 'Laminas\Cache' into:
  [0] Do not inject
  [1] config/modules.config.php
  [2] config/development.config.php.dist
  Make your selection (default is 1):

Remember this option for other packages of the same type? (Y/n)
N

ここでN(No)にするとパッケージ毎にどうするか聞かれるのでだいたいデフォルトでいいんじゃないですかね・・・

Y(Yes)を選んでも以下の項目は再度聞かれます。Developmentモードのときだけ必要なやつの設定ですね。

Please select which config file you wish to inject 'Laminas\DeveloperTools' into:
  [0] Do not inject
  [1] config/modules.config.php
  [2] config/development.config.php.dist
  Make your selection (default is 1):
N

これで導入は完了。
ご丁寧にVagrantとDockerのローカル環境の設定があるので今回はDockerで起動してみます。

$ docker-compose up -d --build

http://localhost:8080にアクセスすると以下のような画面が表示されます。
スクリーンショット 2020-07-27 0.48.03.png

自分たちが開発していくアプリケーションはmodules/Application/srcになります。以前ZendExpressiveのv2系をやったことがあるんですがまた違ったディレクトリ構造ですね・・・
PSR-7,DI,UnitTestがデフォルトでついてる(任意選択)のは今どきのPHPフレームワークって感じですね。
とはいえPSR-7といいつつlaminas-psr7bridgeでLaminas独自の型に変換してるので純粋なPSR-7じゃないっぽい?

公式ドキュメントも豊富なので良さそうですね。とはいえフルスタックなフレームワークなだけに機能豊富で一通りの使い方を覚えるのには骨が折れそう・・・

15
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
4