samurai framework 紹介
TRANSCRIPT
株式会社BEFOOL
開発者紹介
名前: 木内智史之介
経歴:
北諏訪小学校 -> 引っ越し -> 荒幡小学校
山口中学校
所沢高等学校
東京マルチメディア専門学校
株式会社ジェイケン(現在はドリコムに吸収合併されました)
独立 -> 株式会社BEFOOL
株式会社BEFOOL
Samurai Frameworkってなに?
PHPのフルスタックフレームワークです。
Mapleから派生しました。
Mapleって?
• 4~5年前くらいにEthna、symfonyと並んで紹介されていたフレームワーク
• 2年前くらいにMaple4を作ろうという流れに
• その際にコミッタになりました
• Maple4は残念ながら開発は事実上の停止状態にあります
Mapleの基本的な理念を引き継いでいます
Maple4開発時の議論に上がった内容を、(主にDIContainer部分に関して)取り入れています。
DIContainerを軸に動作します
O/RマッパーActiveGatewayを備えています
PHPSpecを利用したしたテスト機構を備えています
株式会社BEFOOL
Samurai Framework WEBサイト
( ゚д゚)_(__つ/ ̄ ̄ ̄/_
\/ / ̄ ̄ ̄( ゚д゚ )
_(__つ/ ̄ ̄ ̄/_
\//
 ̄ ̄ ̄( ゚
д゚)_(__つ/ ̄ ̄ ̄/_
\/ / ̄ ̄ ̄
( ゚д゚ )_(__つ/ ̄ ̄ ̄/_
\//
 ̄ ̄ ̄
株式会社BEFOOL
FilterChainの流れ
クライアント(ブラウザ)
Action
Filter1
Filter2
Filter3
Filter4
Filter5
prefilter postfilter
株式会社BEFOOL
Filterの種類
Convert (リクエストパラメータの変換)
Validate (入力チェック)
Auth (認証)
Token (リクエストの簡易チェック)
DIContainer (DIContainer初期化)
ActiveGateway (ActiveGateway利用準備)
View (テンプレートの表示など)
Debug (デバッグ情報の表示)
などなど、Samurai Frameworkでは多くの処理をFilterで実装しています。
株式会社BEFOOL
ディレクトリ構成
bin/
component/
action/
filter/
config/
samurai/
activegateway/
routing/
library/
locale/
log/
migrate/
db/
skeleton/
spec/
temp/
template/
www/
株式会社BEFOOL
インストール方法
pearコマンド利用します
# pear channel-discover pear.samurai-fw.org# pear install –f samurai/Samurai
# samuraiUsage:
samurai [option] [command] [command-option] [args...]Options:
--version, -[vV] Print version and exit successfully.--help, -[hH] Print this help and exit successfully.
Commands:add-project Add Project.add-application Add Application.add-action Add Action.add-template Add Template.
株式会社BEFOOL
プログラミングの流れ
add-projectする
while(1){
add-specする
add-componentする
samurai.diconに追加する
失敗 / 成功
}
while(1){
add-actionする
}
株式会社BEFOOL
閑話:PHPSpecに関して
Samurai FrameworkではSpecのRunnerとしてPHPSpecを採用しているのですが…
PHPSpecって開発停止している…よね…?
なぜ採用したし…
PHPSpecのようなBDDフレームワークってほかにないですかー?
株式会社BEFOOL
DIContainerって?
DependencyInjection(依存性注入)
クラスは多くの場合他クラスに依存するもの
その依存性の解決を個々のクラスに任せるのは大変
初期化の方法が変わればnewしてる箇所すべてに影響がでる
クラス名の変更が容易ではない
• モッククラスを適当に用意しておくことがしづらい
• クラス間の依存関係が見えづらい
DIContainerが解決!
function initMethod(){
$this->SomeComponent = new SomeComponent();$module = $this->loadModule(‘some’);
}
SomeManager:class: Mock_Some_Manager
SomeManager:class: Some_Manager
株式会社BEFOOL
DIContainerの書き方
FooManager:class: Foo_Manager
BarManager:class: Bar_Manager
ZooManager:class: Zoo_Manager
samurai.dicon foo/Manager.class.php
class Foo_Manager{
public $BarManager;public $ZooManager;
}
自動的に差し込んでくれる
株式会社BEFOOL
いくつかのクラス初期化方法をサポート
FooManager:class: Foo_Manager
通常
毎回新しいインスタンスを取得
FooManager:class: Foo_Managerinstance: prototype
コンストラクタに引数
FooManager:class: Foo_Managerargs: [1, 2, $BarManager]
setter
FooManager:class: Foo_Managersetter:
db: $DB
初期化メソッド
FooManager:class: Foo_ManagerinitMethod: initargs: [$DB]
株式会社BEFOOL
ライバル
cakePHP
なめんなこら!
symfony
やんのかこら!
ZendFramework
腰抜かしてやんよ!
CodeIgniter
おらおらー
Ethna
おらおらー