Intercepor プラグインを作ってみました。
package.xml はもちろんのこと、 DocBlock コメントも皆無ですが...
設定ポイントの解説は id:perezvon さんの http://d.hatena.ne.jp/perezvon/20070126/1169800012 を真似させていただきました。
Piece_Unity_Plugin_Interceptor_Mobile
携帯端末の判定、レンダラ設定の上書き、出力エンコーディング変換を行うための Interceptor 集 (ダウンロード)
Interceptor_MobileUserAgent で User-Agent の判定を行い、Piece_Unity_Context の attribute に以下の値を設定します。
- MobileUserAgent_detector (Net_UserAgent_Mobile_xxx のインスタンス)
- MobileUserAgent_isMobile (携帯端末か否か)
- MobileUserAgent_supportsCookie (Cookie に対応する端末か否か)
Interceptor_MobileRenderer と Interceptor_MobileOutputFilter では MobileUserAgent_isMobile の値を調べるので、Interceptor_MobileUserAgent はこれらより先に読み込まれなければいけません。
Piece_Unity_Plugin_Interceptor_MobileUserAgent の設定ポイント
| キー | 説明 | デフォルト値 |
|---|---|---|
| forcedUserAgent | $_SERVER['HTTP_USER_AGENT'] を上書きする文字列 (開発用) | null |
| lazyDetection | Net_UserAgent_Mobile を用いずに大雑把な判定をするか否か | false |
Piece_Unity_Plugin_Interceptor_MobileRenderer の設定ポイント
Piece_Unity_Plugin_Renderer_xxx の設定を上書きするので、設定ポイントは View プラグインの renderer 設定ポイントで指定されたレンダラに依存します。
例えば携帯端末用のテンプレートを別にしたい場合は以下のように設定します。
携帯端末用のテンプレートは PC 用のテンプレートと同じエンコーディング (UTF-8 を推奨) で作成し、meta 要素の Content-Type には "text/html; charset=Shift_JIS" と、Interceptor_MobileOutputFilter の headerCharset と同じエンコーディングを指定します。
(エディタによってはファイルのエンコーディングと meta 要素とで異るエンコーディングが指定されている旨の警告が出ることがあります)
- name: InterceptorChain
point:
- name: interceptors
type: extension
value:
- Interceptor_NullByteAttackPreventation
- Interceptor_SessionStart
- Interceptor_MobileUserAgent
- Interceptor_MobileRenderer
- Interceptor_MobileOutputFilter
- Interceptor_Authentication
- name: Renderer_Flexy
point:
- name: templateDir
type: configuration
value: ../webapp/templates/FlowName
- name: compileDir
type: configuration
value: ../webapp/compiled-templates/FlowName
- name: useLayout
type: configuration
value: true
- name: layoutView
type: configuration
value: Layout
- name: layoutDirectory
type: configuration
value: ../webapp/templates/Layout
- name: layoutCompileDirectory
type: configuration
value: ../webapp/compiled-templates/Layout
- name: Interceptor_MobileRenderer
point:
- name: templateDir
type: configuration
value: ../webapp/templates/FlowName_Mobile
- name: compileDir
type: configuration
value: ../webapp/compiled-templates/FlowName_Mobile
- name: layoutView
type: configuration
value: Layout_Mobile
Cookie をサポートしていない携帯端末で同一フロー内リダイレクトする際には、renderer が Renderer_Redirection でない限りは上書きされないので、アクションクラスの _prepare() メソッドに以下のような記述をします。
if (!$this->_payload->getAttribute('MobileUserAgent_supportsCookie')) {
$config = &$this->_payload->getConfiguration();
$config->setConfiguration('Renderer_Redirection', 'addSessionID', true);
}
Piece_Unity_Plugin_Interceptor_GarbageCollection
一時ファイルのガーベッジコレクションを行うための Interceptor (ダウンロード)
設定ポイント
| キー | 説明 | デフォルト値 |
|---|---|---|
| targetDirectories | ガーベッジコレクション対象ディレクトリ | array() |
| probability | ガーベッジコレクション実行確率の分子 | 1 |
| divisor | ガーベッジコレクション実行確率の分母 | 1000 |
| lifeTime | 一時ファイルの有効期限 (秒) | 3600 |
| recursionDepth | 再帰深度 | 0 |
| removeEmptySubDirectory | 空のサブディレクトリを削除するか否か | false |
| byAccessTime | 有効期限をファイルの最終アクセス時刻で判定するか否か デフォルトではファイルの更新時刻で判定する |
false |