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 // OS_WINDOWS constant was defined
14 if (substr(PHP_OS, 0, 3) == 'WIN'
15 && !defined('OS_WINDOWS')) {
16 define('OS_WINDOWS', true);
17 } elseif (!defined('OS_WINDOWS')) {
18 define('OS_WINDOWS', false);
21 if (!defined('PATH_SEPARATOR')) {
23 /** include_path separator(Windows) */
24 define('PATH_SEPARATOR', ';');
26 /** include_path separator(Unix) */
27 define('PATH_SEPARATOR', ':');
30 if (!defined('DIRECTORY_SEPARATOR')) {
32 /** directory separator(Windows) */
33 define('DIRECTORY_SEPARATOR', '\\');
35 /** separator(Unix) */
36 define('DIRECTORY_SEPARATOR', '/');
41 define('ETHNA_VERSION', '2.5.0-preview1');
45 * PEAR非依存、かつ互換性を維持するためのもの
47 define('ETHNA_ERROR_DUMMY', 'dummy');
49 /** Ethnaベースディレクトリ定義 */
50 define('ETHNA_BASE', dirname(__FILE__));
52 require_once ETHNA_BASE . '/class/Ethna_ActionClass.php';
53 require_once ETHNA_BASE . '/class/Ethna_ActionError.php';
54 require_once ETHNA_BASE . '/class/Ethna_ActionForm.php';
55 require_once ETHNA_BASE . '/class/Ethna_AppManager.php';
56 require_once ETHNA_BASE . '/class/Ethna_AppObject.php';
57 require_once ETHNA_BASE . '/class/Ethna_AppSQL.php';
58 require_once ETHNA_BASE . '/class/Ethna_AppSearchObject.php';
59 require_once ETHNA_BASE . '/class/Ethna_Backend.php';
60 require_once ETHNA_BASE . '/class/Ethna_CacheManager.php';
61 require_once ETHNA_BASE . '/class/Ethna_Config.php';
62 require_once ETHNA_BASE . '/class/Ethna_Controller.php';
63 require_once ETHNA_BASE . '/class/Ethna_ClassFactory.php';
64 require_once ETHNA_BASE . '/class/Ethna_DB.php';
65 require_once ETHNA_BASE . '/class/Ethna_Error.php';
66 require_once ETHNA_BASE . '/class/Ethna_Filter.php';
67 require_once ETHNA_BASE . '/class/Ethna_Handle.php';
68 require_once ETHNA_BASE . '/class/Ethna_I18N.php';
69 require_once ETHNA_BASE . '/class/Ethna_Logger.php';
70 require_once ETHNA_BASE . '/class/Ethna_MailSender.php';
71 require_once ETHNA_BASE . '/class/Ethna_Session.php';
72 require_once ETHNA_BASE . '/class/Ethna_Generator.php';
73 require_once ETHNA_BASE . '/class/Ethna_UrlHandler.php';
74 require_once ETHNA_BASE . '/class/Ethna_Util.php';
75 require_once ETHNA_BASE . '/class/Ethna_ViewClass.php';
76 require_once ETHNA_BASE . '/class/View/Ethna_View_List.php';
77 require_once ETHNA_BASE . '/class/Ethna_Plugin.php';
78 require_once ETHNA_BASE . '/class/Ethna_Renderer.php';
79 require_once ETHNA_BASE . '/class/CLI/Ethna_CLI_ActionClass.php';
81 if (extension_loaded('soap')) {
82 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_ActionForm.php';
83 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_Gateway.php';
84 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_GatewayGenerator.php';
85 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_Util.php';
86 require_once ETHNA_BASE . '/class/SOAP/Ethna_SOAP_WsdlGenerator.php';
90 define('GATEWAY_WWW', 1);
93 define('GATEWAY_CLI', 2);
96 define('GATEWAY_XMLRPC', 3);
99 define('GATEWAY_SOAP', 4);
103 define('DB_TYPE_RW', 1);
106 define('DB_TYPE_RO', 2);
109 define('DB_TYPE_MISC', 3);
113 define('VAR_TYPE_INT', 1);
116 define('VAR_TYPE_FLOAT', 2);
119 define('VAR_TYPE_STRING', 3);
122 define('VAR_TYPE_DATETIME', 4);
125 define('VAR_TYPE_BOOLEAN', 5);
128 define('VAR_TYPE_FILE', 6);
132 define('FORM_TYPE_TEXT', 1);
134 /** フォーム型: password */
135 define('FORM_TYPE_PASSWORD', 2);
137 /** フォーム型: textarea */
138 define('FORM_TYPE_TEXTAREA', 3);
141 define('FORM_TYPE_SELECT', 4);
144 define('FORM_TYPE_RADIO', 5);
146 /** フォーム型: checkbox */
147 define('FORM_TYPE_CHECKBOX', 6);
150 define('FORM_TYPE_SUBMIT', 7);
153 define('FORM_TYPE_FILE', 8);
156 define('FORM_TYPE_BUTTON', 9);
159 define('FORM_TYPE_HIDDEN', 10);
163 define('E_GENERAL', 1);
165 /** エラーコード: DB接続エラー */
166 define('E_DB_CONNECT', 2);
168 /** エラーコード: DB設定なし */
169 define('E_DB_NODSN', 3);
171 /** エラーコード: DBクエリエラー */
172 define('E_DB_QUERY', 4);
174 /** エラーコード: DBユニークキーエラー */
175 define('E_DB_DUPENT', 5);
177 /** エラーコード: DB種別エラー */
178 define('E_DB_INVALIDTYPE', 6);
180 /** エラーコード: セッションエラー(有効期限切れ) */
181 define('E_SESSION_EXPIRE', 16);
183 /** エラーコード: セッションエラー(IPアドレスチェックエラー) */
184 define('E_SESSION_IPCHECK', 17);
186 /** エラーコード: アクション未定義エラー */
187 define('E_APP_UNDEFINED_ACTION', 32);
189 /** エラーコード: アクションクラス未定義エラー */
190 define('E_APP_UNDEFINED_ACTIONCLASS', 33);
192 /** エラーコード: アプリケーションオブジェクトID重複エラー */
193 define('E_APP_DUPENT', 34);
195 /** エラーコード: アプリケーションメソッドが存在しない */
196 define('E_APP_NOMETHOD', 35);
198 /** エラーコード: ロックエラー */
199 define('E_APP_LOCK', 36);
201 /** エラーコード: 読み込みエラー */
202 define('E_APP_READ', 37);
204 /** エラーコード: 書き込みエラー */
205 define('E_APP_WRITE', 38);
207 /** エラーコード: CSV分割エラー(行継続) */
208 define('E_UTIL_CSV_CONTINUE', 64);
210 /** エラーコード: フォーム値型エラー(スカラー引数に配列指定) */
211 define('E_FORM_WRONGTYPE_SCALAR', 128);
213 /** エラーコード: フォーム値型エラー(配列引数にスカラー指定) */
214 define('E_FORM_WRONGTYPE_ARRAY', 129);
216 /** エラーコード: フォーム値型エラー(整数型) */
217 define('E_FORM_WRONGTYPE_INT', 130);
219 /** エラーコード: フォーム値型エラー(浮動小数点数型) */
220 define('E_FORM_WRONGTYPE_FLOAT', 131);
222 /** エラーコード: フォーム値型エラー(日付型) */
223 define('E_FORM_WRONGTYPE_DATETIME', 132);
225 /** エラーコード: フォーム値型エラー(BOOL型) */
226 define('E_FORM_WRONGTYPE_BOOLEAN', 133);
228 /** エラーコード: フォーム値型エラー(FILE型) */
229 define('E_FORM_WRONGTYPE_FILE', 134);
231 /** エラーコード: フォーム値必須エラー */
232 define('E_FORM_REQUIRED', 135);
234 /** エラーコード: フォーム値最小値エラー(整数型) */
235 define('E_FORM_MIN_INT', 136);
237 /** エラーコード: フォーム値最小値エラー(浮動小数点数型) */
238 define('E_FORM_MIN_FLOAT', 137);
240 /** エラーコード: フォーム値最小値エラー(文字列型) */
241 define('E_FORM_MIN_STRING', 138);
243 /** エラーコード: フォーム値最小値エラー(日付型) */
244 define('E_FORM_MIN_DATETIME', 139);
246 /** エラーコード: フォーム値最小値エラー(ファイル型) */
247 define('E_FORM_MIN_FILE', 140);
249 /** エラーコード: フォーム値最大値エラー(整数型) */
250 define('E_FORM_MAX_INT', 141);
252 /** エラーコード: フォーム値最大値エラー(浮動小数点数型) */
253 define('E_FORM_MAX_FLOAT', 142);
255 /** エラーコード: フォーム値最大値エラー(文字列型) */
256 define('E_FORM_MAX_STRING', 143);
258 /** エラーコード: フォーム値最大値エラー(日付型) */
259 define('E_FORM_MAX_DATETIME', 144);
261 /** エラーコード: フォーム値最大値エラー(ファイル型) */
262 define('E_FORM_MAX_FILE', 145);
264 /** エラーコード: フォーム値文字種(正規表現)エラー */
265 define('E_FORM_REGEXP', 146);
267 /** エラーコード: フォーム値数値(カスタムチェック)エラー */
268 define('E_FORM_INVALIDVALUE', 147);
270 /** エラーコード: フォーム値文字種(カスタムチェック)エラー */
271 define('E_FORM_INVALIDCHAR', 148);
273 /** エラーコード: 確認用エントリ入力エラー */
274 define('E_FORM_CONFIRM', 149);
276 /** エラーコード: キャッシュタイプ不正 */
277 define('E_CACHE_INVALID_TYPE', 192);
279 /** エラーコード: キャッシュ値なし */
280 define('E_CACHE_NO_VALUE', 193);
282 /** エラーコード: キャッシュ有効期限 */
283 define('E_CACHE_EXPIRED', 194);
285 /** エラーコード: キャッシュエラー(その他) */
286 define('E_CACHE_GENERAL', 195);
288 /** エラーコード: プラグインが見つからない */
289 define('E_PLUGIN_NOTFOUND', 196);
291 /** エラーコード: プラグインエラー(その他) */
292 define('E_PLUGIN_GENERAL', 197);
294 if (defined('E_STRICT') == false) {
296 define('E_STRICT', 2048);
299 /** Ethnaグローバル変数: エラーコールバック関数 */
300 $GLOBALS['_Ethna_error_callback_list'] = array();
302 /** Ethnaグローバル変数: エラーメッセージ */
303 $GLOBALS['_Ethna_error_message_list'] = array();
310 * @author Masaki Fujimoto <fujimoto@php.net>
317 * 渡されたオブジェクトが Ethna_Error オブジェクト
320 * @param mixed $data チェックする変数
321 * @param mixed $msgcode チェックするエラーメッセージまたはエラーコード
322 * @return mixed 変数が、Ethna_Error の場合に TRUEを返します。
323 * 第2引数が設定された場合は、さらに 所与された $msgcode
327 function isError($data, $msgcode = NULL)
329 if (!is_object($data)) {
333 $class_name = get_class($data);
334 if (strcasecmp($class_name, 'Ethna_Error') === 0
335 || is_subclass_of($data, 'Ethna_Error')) {
336 if ($msgcode == NULL) {
338 } elseif ($data->getCode() == $msgcode) {
347 * Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_ERROR)
350 * @param string $message エラーメッセージ
351 * @param int $code エラーコード
354 function &raiseError($message, $code = E_GENERAL)
357 if (func_num_args() > 2) {
358 $userinfo = array_slice(func_get_args(), 2);
359 if (count($userinfo) == 1 && is_array($userinfo[0])) {
360 $userinfo = $userinfo[0];
363 $error = new Ethna_Error($message, $code, ETHNA_ERROR_DUMMY, E_USER_ERROR, $userinfo, 'Ethna_Error');
368 * Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_WARNING)
371 * @param string $message エラーメッセージ
372 * @param int $code エラーコード
375 function &raiseWarning($message, $code = E_GENERAL)
378 if (func_num_args() > 2) {
379 $userinfo = array_slice(func_get_args(), 2);
380 if (count($userinfo) == 1 && is_array($userinfo[0])) {
381 $userinfo = $userinfo[0];
385 $error = new Ethna_Error($message, $code, ETHNA_ERROR_DUMMY, E_USER_WARNING, $userinfo, 'Ethna_Error');
390 * Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_NOTICE)
393 * @param string $message エラーメッセージ
394 * @param int $code エラーコード
397 function &raiseNotice($message, $code = E_GENERAL)
400 if (func_num_args() > 2) {
401 $userinfo = array_slice(func_get_args(), 2);
402 if (count($userinfo) == 1 && is_array($userinfo[0])) {
403 $userinfo = $userinfo[0];
407 $error = new Ethna_Error($message, $code, ETHNA_ERROR_DUMMY, E_USER_NOTICE, $userinfo, 'Ethna_Error');
412 * エラー発生時の(フレームワークとしての)コールバック関数を設定する
415 * @param mixed string:コールバック関数名 array:コールバッククラス(名|オブジェクト)+メソッド名
418 function setErrorCallback($callback)
420 $GLOBALS['_Ethna_error_callback_list'][] = $callback;
424 * エラー発生時の(フレームワークとしての)コールバック関数をクリアする
429 function clearErrorCallback()
431 $GLOBALS['_Ethna_error_callback_list'] = array();
435 * エラー発生時の処理を行う(コールバック関数/メソッドを呼び出す)
438 * @param object Ethna_Error Ethna_Errorオブジェクト
441 function handleError(&$error)
443 for ($i = 0; $i < count($GLOBALS['_Ethna_error_callback_list']); $i++) {
444 $callback =& $GLOBALS['_Ethna_error_callback_list'][$i];
445 if (is_array($callback) == false) {
446 call_user_func($callback, $error);
447 } else if (is_object($callback[0])) {
448 $object =& $callback[0];
449 $method = $callback[1];
451 // perform some more checks?
452 $object->$method($error);
455 call_user_func($callback, $error);