サンプルアプリケーションを動作させるには?
(Piece_Unity >= 1.0.0)
バージョン0.12.0までパッケージに含まれていたサンプルアプリケーションは、Piece_Examples_Basicsパッケージとして独立しています。まず最初にPiece_Examples_Basicsパッケージをインストールしてください。インストール方法は下記のとおりです。
pear channel-discover pear.piece-framework.com pear install piece/Piece_Examples_Basics
ドキュメントルートの設定が可能な場合
ドキュメントルートの設定が可能な場合、サンプルアプリケーションを動作させるためには下記の準備が必要です。
- data_dir/Piece_Examples_Basics/web/htdocsディレクトリをWebサーバのドキュメントルートに設定する。
- data_dir/Piece_Examples_Basics/web/webapp/sessionsディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- data_dir/Piece_Examples_Basics/web/webapp/cacheディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- data_dir/Piece_Examples_Basics/web/webapp/cache/flowsディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- data_dir/Piece_Examples_Basics/web/webapp/cache/validationsディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- data_dir/Piece_Examples_Basics/web/webapp/compiled-templatesディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
ここまでの準備が整えば、Webサーバを起動し、サンプルアプリケーションを動作させることができるでしょう。
なお、data_dirはPEAR data directoryです。下記のコマンドを実行すると、お使いの環境のPEAR data directoryを確認することができます。
pear config-show
ドキュメントルートの設定が不可能な場合
ドキュメントルートの設定が不可能な場合、サンプルアプリケーションを動作させるためには下記の準備が必要です。なお、ここでは次の環境を想定しています。お使いの環境により適宜読み替えてください。
- ドキュメントルート
- /path/to/home/www
- サンプルアプリケーション配備先ディレクトリ
- /path/to/home/www/basics
- PEARパッケージ配備先ディレクトリ
- /path/to/home/www/basics/imports/pear
- Spyc配備先ディレクトリ
- /path/to/home/www/basics/imports/spyc-0.2.5
ディレクトリ構造:
/path/to/home/www/basics
|
|-authenticate.php
|
+--css
|
|-flow-execution-expired.php
|
+--images
|
+--imports
| |
| +--pear
| |
| +--spyc-0.2.5
|
|-index.php
|
+--js
|
|-protected-resource.php
|
|-register-with-exclusive-mode-and-ahah.php
|
|-register-with-exclusive-mode.php
|
|-register-with-non-exclusive-mode.php
|
+--webapp
最初にディレクトリ構造を準備します。
- data_dir/Piece_Examples_Basics/web/htdocsディレクトリを/path/to/home/wwwにコピーする。
- /path/to/home/www/htdocsを/path/to/home/www/basicsにリネームする。
- data_dir/Piece_Examples_Basics/web/webappディレクトリを/path/to/home/www/basicsにコピーする。
次に/path/to/home/www/basicsの直下にあるファイルを下記のように変更します。
- /../../importsを/importsに置換します。
- /../webappを/webappに置換します。
例えば/path/to/home/www/basics/index.phpは下記のようになります。
<?php ... error_reporting(E_ALL); if (file_exists(dirname(__FILE__) . '/imports')) { set_include_path(dirname(__FILE__) . '/imports/pear' . PATH_SEPARATOR . dirname(__FILE__) . '/imports/spyc-0.2.5' ); } require_once 'Piece/Unity.php'; require_once 'Piece/Unity/Error.php'; Piece_Unity_Error::pushCallback(create_function('$error', 'var_dump($error); return ' . PEAR_ERRORSTACK_DIE . ';')); $base = dirname(__FILE__) . '/webapp'; ...
続いてPiece_Unity設定ファイル(piece-unity-config.yaml)も下記のように変更します。
- ../webappを./webappに置換します。
- Dispatcher_Continuationプラグインの設定ポイントflowMappingsのurlの値の先頭に/basicsを付加します。
- Interceptor_Authenticationプラグインの設定ポイントresourcesの値の先頭に/basicsを付加します。
- Configurator_Proxyプラグインの設定を削除します。
- Configurator_AppRootプラグインの設定ポイントappRootPathの値に/basicsを設定します。
変更後は下記のようになります。
...
- name: Dispatcher_Continuation
point:
- name: actionDirectory
type: configuration
value: ./webapp/actions
- name: cacheDirectory
type: configuration
value: ./webapp/cache/flows
- name: enableGC
type: configuration
value: true
- name: gcExpirationTime
type: configuration
value: 30
- name: useGCFallback
type: configuration
value: true
- name: gcFallbackURL
type: configuration
value: "http://example.org/basics/flow-execution-expired.php"
- name: useFlowMappings
type: configuration
value: true
- name: configDirectory
type: configuration
value: ./webapp/config/flows
- name: flowMappings
type: configuration
value:
- url: /basics/register-with-non-exclusive-mode.php
flowName: Registration
isExclusive: false
- url: /basics/register-with-exclusive-mode.php
flowName: Registration
isExclusive: true
- url: /basics/register-with-exclusive-mode-and-ahah.php
flowName: Registration
isExclusive: true
- url: /basics/authenticate.php
flowName: Authentication
isExclusive: true
- url: /basics/protected-resource.php
flowName: ProtectedResource
isExclusive: false
- name: Dispatcher_Simple
point:
- name: actionDirectory
type: configuration
value: ./webapp/actions
- name: View
point:
- name: renderer
type: extension
value: Renderer_Flexy
- name: InterceptorChain
point:
- name: interceptors
type: extension
value:
- Interceptor_NullByteAttackPreventation
- Interceptor_SessionStart
- Interceptor_Authentication
- name: Renderer_Flexy
point:
- name: useLayout
type: configuration
value: true
- name: layoutView
type: configuration
value: Layout_Layout
- name: templateDir
type: configuration
value: ./webapp/templates
- name: compileDir
type: configuration
value: ./webapp/compiled-templates
- name: Interceptor_Authentication
point:
- name: url
type: configuration
value: "http://example.org/basics/authenticate.php"
- name: resources
type: configuration
value:
- /basics/protected-resource.php
- name: Configurator_Validation
point:
- name: configDirectory
type: configuration
value: ./webapp/config/validations
- name: cacheDirectory
type: configuration
value: ./webapp/cache/validations
- name: useUnderscoreAsDirectorySeparator
type: configuration
value: true
- name: template
type: configuration
value: Common
- name: Configurator_AppRoot
point:
- name: appRootPath
type: configuration
value: /basics
# Local Variables:
# mode: conf-colon
# coding: iso-8859-1
# tab-width: 2
# indent-tabs-mode: nil
# End:
次に/path/to/home/www/basics/webapp/actions/RegistrationAction.phpを変更します。下記のようにURLの先頭に/basicsを付加します。
<?php ... function _setTitle() { if ($_SERVER['SCRIPT_NAME'] == '/basics/register-with-non-exclusive-mode.php') { $title = 'A.1. An application component for registration. *non-exclusive*'; } elseif ($_SERVER['SCRIPT_NAME'] == '/basics/register-with-exclusive-mode.php') { $title = 'A.2. An application component for registration. *exclusive*'; } elseif ($_SERVER['SCRIPT_NAME'] == '/basics/register-with-exclusive-mode-and-ahah.php') { $title = 'A.3. An application component with AHAH for registration. *exclusive*'; } $viewElement = &$this->_context->getViewElement(); $viewElement->setElement('title', $title); } ...
最後にいくつかのディレクトリのパーミッションを適切なものに変更します。
- /path/to/home/www/basics/webapp/sessionsディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- /path/to/home/www/basics/webapp/cacheディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- /path/to/home/www/basics/webapp/cache/flowsディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- /path/to/home/www/basics/webapp/cache/validationsディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
- /path/to/home/www/basics/webapp/compiled-templatesディレクトリに対して、Webサーバのプロセスが読み書きできるパーミッションを設定する。
ここまでの準備が整えば、サンプルアプリケーションを動作させることができるでしょう。また、Webからアクセスされてはならないディレクトリに対して.htaccessによる適切な設定を行う必要があることに注意してください。

