2 // vim: foldmethod=marker
6 * @author Masaki Fujimoto <fujimoto@php.net>
7 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12 /** Ethna depends on PEAR */
13 require_once 'PEAR.php';
15 if (!defined('PATH_SEPARATOR')) {
17 /** include_path separator(Windows) */
18 define('PATH_SEPARATOR', ';');
20 /** include_path separator(Unix) */
21 define('PATH_SEPARATOR', ':');
24 if (!defined('DIRECTORY_SEPARATOR')) {
26 /** directory separator(Windows) */
27 define('DIRECTORY_SEPARATOR', '\\');
29 /** separator(Unix) */
30 define('DIRECTORY_SEPARATOR', '/');
35 define('ETHNA_VERSION', '2.3.2');
37 /** Ethnaベースディレクトリ定義 */
38 define('ETHNA_BASE', dirname(__FILE__));
40 require_once ETHNA_BASE . '/class/Ethna_ActionClass.php';
41 require_once ETHNA_BASE . '/class/Ethna_ActionError.php';
42 require_once ETHNA_BASE . '/class/Ethna_ActionForm.php';
43 require_once ETHNA_BASE . '/class/Ethna_AppManager.php';
44 require_once ETHNA_BASE . '/class/Ethna_AppObject.php';
45 require_once ETHNA_BASE . '/class/Ethna_AppSQL.php';
46 require_once ETHNA_BASE . '/class/Ethna_AppSearchObject.php';
47 require_once ETHNA_BASE . '/class/Ethna_Backend.php';
48 require_once ETHNA_BASE . '/class/Ethna_CacheManager.php';
49 require_once ETHNA_BASE . '/class/Ethna_Config.php';
50 require_once ETHNA_BASE . '/class/Ethna_Controller.php';
51 require_once ETHNA_BASE . '/class/Ethna_ClassFactory.php';
52 require_once ETHNA_BASE . '/class/Ethna_DB.php';
53 require_once ETHNA_BASE . '/class/Ethna_Error.php';
54 require_once ETHNA_BASE . '/class/Ethna_Filter.php';
55 require_once ETHNA_BASE . '/class/Ethna_Handle.php';
56 require_once ETHNA_BASE . '/class/Ethna_I18N.php';
57 require_once ETHNA_BASE . '/class/Ethna_Logger.php';
58 require_once ETHNA_BASE . '/class/Ethna_MailSender.php';
59 require_once ETHNA_BASE . '/class/Ethna_Session.php';
60 require_once ETHNA_BASE . '/class/Ethna_Generator.php';
61 require_once ETHNA_BASE . '/class/Ethna_UrlHandler.php';
62 require_once ETHNA_BASE . '/class/Ethna_Util.php';
63 require_once ETHNA_BASE . '/class/Ethna_ViewClass.php';
64 require_once ETHNA_BASE . '/class/View/Ethna_View_List.php';
65 require_once ETHNA_BASE . '/class/Ethna_Plugin.php';
66 require_once ETHNA_BASE . '/class/Ethna_Renderer.php';
67 require_once ETHNA_BASE . '/class/CLI/Ethna_CLI_ActionClass.php';
69 if (extension_loaded('soap')) {
70 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_ActionForm.php';
71 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_Gateway.php';
72 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_GatewayGenerator.php';
73 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_Util.php';
74 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_WsdlGenerator.php';
78 define('LANG_EN', 'en');
80 /** クライアント言語定義: 日本語 */
81 define('LANG_JA', 'ja');
85 define('GATEWAY_WWW', 1);
88 define('GATEWAY_CLI', 2);
91 define('GATEWAY_XMLRPC', 3);
94 define('GATEWAY_SOAP', 4);
98 define('DB_TYPE_RW', 1);
101 define('DB_TYPE_RO', 2);
104 define('DB_TYPE_MISC', 3);
108 define('VAR_TYPE_INT', 1);
111 define('VAR_TYPE_FLOAT', 2);
114 define('VAR_TYPE_STRING', 3);
117 define('VAR_TYPE_DATETIME', 4);
120 define('VAR_TYPE_BOOLEAN', 5);
123 define('VAR_TYPE_FILE', 6);
127 define('FORM_TYPE_TEXT', 1);
129 /** フォーム型: password */
130 define('FORM_TYPE_PASSWORD', 2);
132 /** フォーム型: textarea */
133 define('FORM_TYPE_TEXTAREA', 3);
136 define('FORM_TYPE_SELECT', 4);
139 define('FORM_TYPE_RADIO', 5);
141 /** フォーム型: checkbox */
142 define('FORM_TYPE_CHECKBOX', 6);
145 define('FORM_TYPE_SUBMIT', 7);
148 define('FORM_TYPE_FILE', 8);
151 define('FORM_TYPE_BUTTON', 9);
154 define('FORM_TYPE_HIDDEN', 10);
158 define('E_GENERAL', 1);
160 /** エラーコード: DB接続エラー */
161 define('E_DB_CONNECT', 2);
163 /** エラーコード: DB設定なし */
164 define('E_DB_NODSN', 3);
166 /** エラーコード: DBクエリエラー */
167 define('E_DB_QUERY', 4);
169 /** エラーコード: DBユニークキーエラー */
170 define('E_DB_DUPENT', 5);
172 /** エラーコード: DB種別エラー */
173 define('E_DB_INVALIDTYPE', 6);
175 /** エラーコード: セッションエラー(有効期限切れ) */
176 define('E_SESSION_EXPIRE', 16);
178 /** エラーコード: セッションエラー(IPアドレスチェックエラー) */
179 define('E_SESSION_IPCHECK', 17);
181 /** エラーコード: アクション未定義エラー */
182 define('E_APP_UNDEFINED_ACTION', 32);
184 /** エラーコード: アクションクラス未定義エラー */
185 define('E_APP_UNDEFINED_ACTIONCLASS', 33);
187 /** エラーコード: アプリケーションオブジェクトID重複エラー */
188 define('E_APP_DUPENT', 34);
190 /** エラーコード: アプリケーションメソッドが存在しない */
191 define('E_APP_NOMETHOD', 35);
193 /** エラーコード: ロックエラー */
194 define('E_APP_LOCK', 36);
196 /** エラーコード: 読み込みエラー */
197 define('E_APP_READ', 37);
199 /** エラーコード: 書き込みエラー */
200 define('E_APP_WRITE', 38);
202 /** エラーコード: CSV分割エラー(行継続) */
203 define('E_UTIL_CSV_CONTINUE', 64);
205 /** エラーコード: フォーム値型エラー(スカラー引数に配列指定) */
206 define('E_FORM_WRONGTYPE_SCALAR', 128);
208 /** エラーコード: フォーム値型エラー(配列引数にスカラー指定) */
209 define('E_FORM_WRONGTYPE_ARRAY', 129);
211 /** エラーコード: フォーム値型エラー(整数型) */
212 define('E_FORM_WRONGTYPE_INT', 130);
214 /** エラーコード: フォーム値型エラー(浮動小数点数型) */
215 define('E_FORM_WRONGTYPE_FLOAT', 131);
217 /** エラーコード: フォーム値型エラー(日付型) */
218 define('E_FORM_WRONGTYPE_DATETIME', 132);
220 /** エラーコード: フォーム値型エラー(BOOL型) */
221 define('E_FORM_WRONGTYPE_BOOLEAN', 133);
223 /** エラーコード: フォーム値型エラー(FILE型) */
224 define('E_FORM_WRONGTYPE_FILE', 134);
226 /** エラーコード: フォーム値必須エラー */
227 define('E_FORM_REQUIRED', 135);
229 /** エラーコード: フォーム値最小値エラー(整数型) */
230 define('E_FORM_MIN_INT', 136);
232 /** エラーコード: フォーム値最小値エラー(浮動小数点数型) */
233 define('E_FORM_MIN_FLOAT', 137);
235 /** エラーコード: フォーム値最小値エラー(文字列型) */
236 define('E_FORM_MIN_STRING', 138);
238 /** エラーコード: フォーム値最小値エラー(日付型) */
239 define('E_FORM_MIN_DATETIME', 139);
241 /** エラーコード: フォーム値最小値エラー(ファイル型) */
242 define('E_FORM_MIN_FILE', 140);
244 /** エラーコード: フォーム値最大値エラー(整数型) */
245 define('E_FORM_MAX_INT', 141);
247 /** エラーコード: フォーム値最大値エラー(浮動小数点数型) */
248 define('E_FORM_MAX_FLOAT', 142);
250 /** エラーコード: フォーム値最大値エラー(文字列型) */
251 define('E_FORM_MAX_STRING', 143);
253 /** エラーコード: フォーム値最大値エラー(日付型) */
254 define('E_FORM_MAX_DATETIME', 144);
256 /** エラーコード: フォーム値最大値エラー(ファイル型) */
257 define('E_FORM_MAX_FILE', 145);
259 /** エラーコード: フォーム値文字種(正規表現)エラー */
260 define('E_FORM_REGEXP', 146);
262 /** エラーコード: フォーム値数値(カスタムチェック)エラー */
263 define('E_FORM_INVALIDVALUE', 147);
265 /** エラーコード: フォーム値文字種(カスタムチェック)エラー */
266 define('E_FORM_INVALIDCHAR', 148);
268 /** エラーコード: 確認用エントリ入力エラー */
269 define('E_FORM_CONFIRM', 149);
271 /** エラーコード: キャッシュタイプ不正 */
272 define('E_CACHE_INVALID_TYPE', 192);
274 /** エラーコード: キャッシュ値なし */
275 define('E_CACHE_NO_VALUE', 193);
277 /** エラーコード: キャッシュ有効期限 */
278 define('E_CACHE_EXPIRED', 194);
280 /** エラーコード: キャッシュエラー(その他) */
281 define('E_CACHE_GENERAL', 195);
283 /** エラーコード: プラグインが見つからない */
284 define('E_PLUGIN_NOTFOUND', 196);
286 /** エラーコード: プラグインエラー(その他) */
287 define('E_PLUGIN_GENERAL', 197);
289 if (defined('E_STRICT') == false) {
291 define('E_STRICT', 2048);
294 /** Ethnaグローバル変数: エラーコールバック関数 */
295 $GLOBALS['_Ethna_error_callback_list'] = array();
297 /** Ethnaグローバル変数: エラーメッセージ */
298 $GLOBALS['_Ethna_error_message_list'] = array();
305 * @author Masaki Fujimoto <fujimoto@php.net>
309 class Ethna extends PEAR
318 * Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_ERROR)
321 * @param string $message エラーメッセージ
322 * @param int $code エラーコード
325 function &raiseError($message, $code = E_GENERAL)
328 if (func_num_args() > 2) {
329 $userinfo = array_slice(func_get_args(), 2);
330 if (count($userinfo) == 1 && is_array($userinfo[0])) {
331 $userinfo = $userinfo[0];
334 return PEAR::raiseError($message, $code, PEAR_ERROR_RETURN, E_USER_ERROR, $userinfo, 'Ethna_Error');
338 * Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_WARNING)
341 * @param string $message エラーメッセージ
342 * @param int $code エラーコード
345 function &raiseWarning($message, $code = E_GENERAL)
348 if (func_num_args() > 2) {
349 $userinfo = array_slice(func_get_args(), 2);
350 if (count($userinfo) == 1 && is_array($userinfo[0])) {
351 $userinfo = $userinfo[0];
354 return PEAR::raiseError($message, $code, PEAR_ERROR_RETURN, E_USER_WARNING, $userinfo, 'Ethna_Error');
358 * Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_NOTICE)
361 * @param string $message エラーメッセージ
362 * @param int $code エラーコード
365 function &raiseNotice($message, $code = E_GENERAL)
368 if (func_num_args() > 2) {
369 $userinfo = array_slice(func_get_args(), 2);
370 if (count($userinfo) == 1 && is_array($userinfo[0])) {
371 $userinfo = $userinfo[0];
374 return PEAR::raiseError($message, $code, PEAR_ERROR_RETURN, E_USER_NOTICE, $userinfo, 'Ethna_Error');
378 * エラー発生時の(フレームワークとしての)コールバック関数を設定する
381 * @param mixed string:コールバック関数名 array:コールバッククラス(名|オブジェクト)+メソッド名
384 function setErrorCallback($callback)
386 $GLOBALS['_Ethna_error_callback_list'][] = $callback;
390 * エラー発生時の(フレームワークとしての)コールバック関数をクリアする
395 function clearErrorCallback()
397 $GLOBALS['_Ethna_error_callback_list'] = array();
401 * エラー発生時の処理を行う(コールバック関数/メソッドを呼び出す)
404 * @param object Ethna_Error Ethna_Errorオブジェクト
407 function handleError(&$error)
409 for ($i = 0; $i < count($GLOBALS['_Ethna_error_callback_list']); $i++) {
410 $callback =& $GLOBALS['_Ethna_error_callback_list'][$i];
411 if (is_array($callback) == false) {
412 call_user_func($callback, $error);
413 } else if (is_object($callback[0])) {
414 $object =& $callback[0];
415 $method = $callback[1];
417 // perform some more checks?
418 $object->$method($error);
420 call_user_func($callback, $error);