Source for file Ethna.php

Documentation is available at Ethna.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna.php
  5.  *
  6.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: Ethna.php 518 2008-05-01 10:46:28Z mumumu-org $
  10.  */
  11.  
  12. /** Ethna depends on PEAR */
  13. require_once 'PEAR.php';
  14.  
  15. if (!defined('PATH_SEPARATOR')) {
  16.     if (OS_WINDOWS{
  17.         /** include_path separator(Windows) */
  18.         define('PATH_SEPARATOR'';');
  19.     else {
  20.         /** include_path separator(Unix) */
  21.         define('PATH_SEPARATOR'':');
  22.     }
  23. }
  24. if (!defined('DIRECTORY_SEPARATOR')) {
  25.     if (OS_WINDOWS{
  26.         /** directory separator(Windows) */
  27.         define('DIRECTORY_SEPARATOR''\\');
  28.     else {
  29.         /** separator(Unix) */
  30.         define('DIRECTORY_SEPARATOR''/');
  31.     }
  32. }
  33.  
  34. /** バージョン定義 */
  35. define('ETHNA_VERSION''2.3.5');
  36.  
  37. /** Ethnaベースディレクトリ定義 */
  38. define('ETHNA_BASE'dirname(__FILE__));
  39.  
  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';
  68.  
  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';
  75. }
  76.  
  77. /** クライアント言語定義: 英語 */
  78. define('LANG_EN''en');
  79.  
  80. /** クライアント言語定義: 日本語 */
  81. define('LANG_JA''ja');
  82.  
  83.  
  84. /** ゲートウェイ: WWW */
  85. define('GATEWAY_WWW'1);
  86.  
  87. /** ゲートウェイ: CLI */
  88. define('GATEWAY_CLI'2);
  89.  
  90. /** ゲートウェイ: XMLRPC */
  91. define('GATEWAY_XMLRPC'3);
  92.  
  93. /** ゲートウェイ: SOAP */
  94. define('GATEWAY_SOAP'4);
  95.  
  96.  
  97. /** DB種別定義: R/W */
  98. define('DB_TYPE_RW'1);
  99.  
  100. /** DB種別定義: R/O */
  101. define('DB_TYPE_RO'2);
  102.  
  103. /** DB種別定義: Misc  */
  104. define('DB_TYPE_MISC'3);
  105.  
  106.  
  107. /** 要素型: 整数 */
  108. define('VAR_TYPE_INT'1);
  109.  
  110. /** 要素型: 浮動小数点数 */
  111. define('VAR_TYPE_FLOAT'2);
  112.  
  113. /** 要素型: 文字列 */
  114. define('VAR_TYPE_STRING'3);
  115.  
  116. /** 要素型: 日付 */
  117. define('VAR_TYPE_DATETIME'4);
  118.  
  119. /** 要素型: 真偽値 */
  120. define('VAR_TYPE_BOOLEAN'5);
  121.  
  122. /** 要素型: ファイル */
  123. define('VAR_TYPE_FILE'6);
  124.  
  125.  
  126. /** フォーム型: text */
  127. define('FORM_TYPE_TEXT'1);
  128.  
  129. /** フォーム型: password */
  130. define('FORM_TYPE_PASSWORD'2);
  131.  
  132. /** フォーム型: textarea */
  133. define('FORM_TYPE_TEXTAREA'3);
  134.  
  135. /** フォーム型: select */
  136. define('FORM_TYPE_SELECT'4);
  137.  
  138. /** フォーム型: radio */
  139. define('FORM_TYPE_RADIO'5);
  140.  
  141. /** フォーム型: checkbox */
  142. define('FORM_TYPE_CHECKBOX'6);
  143.  
  144. /** フォーム型: button */
  145. define('FORM_TYPE_SUBMIT'7);
  146.  
  147. /** フォーム型: file */
  148. define('FORM_TYPE_FILE'8);
  149.  
  150. /** フォーム型: button */
  151. define('FORM_TYPE_BUTTON'9);
  152.  
  153. /** フォーム型: hidden */
  154. define('FORM_TYPE_HIDDEN'10);
  155.  
  156.  
  157. /** エラーコード: 一般エラー */
  158. define('E_GENERAL'1);
  159.  
  160. /** エラーコード: DB接続エラー */
  161. define('E_DB_CONNECT'2);
  162.  
  163. /** エラーコード: DB設定なし */
  164. define('E_DB_NODSN'3);
  165.  
  166. /** エラーコード: DBクエリエラー */
  167. define('E_DB_QUERY'4);
  168.  
  169. /** エラーコード: DBユニークキーエラー */
  170. define('E_DB_DUPENT'5);
  171.  
  172. /** エラーコード: DB種別エラー */
  173. define('E_DB_INVALIDTYPE'6);
  174.  
  175. /** エラーコード: セッションエラー(有効期限切れ) */
  176. define('E_SESSION_EXPIRE'16);
  177.  
  178. /** エラーコード: セッションエラー(IPアドレスチェックエラー) */
  179. define('E_SESSION_IPCHECK'17);
  180.  
  181. /** エラーコード: アクション未定義エラー */
  182. define('E_APP_UNDEFINED_ACTION'32);
  183.  
  184. /** エラーコード: アクションクラス未定義エラー */
  185. define('E_APP_UNDEFINED_ACTIONCLASS'33);
  186.  
  187. /** エラーコード: アプリケーションオブジェクトID重複エラー */
  188. define('E_APP_DUPENT'34);
  189.  
  190. /** エラーコード: アプリケーションメソッドが存在しない */
  191. define('E_APP_NOMETHOD'35);
  192.  
  193. /** エラーコード: ロックエラー */
  194. define('E_APP_LOCK'36);
  195.  
  196. /** エラーコード: 読み込みエラー */
  197. define('E_APP_READ'37);
  198.  
  199. /** エラーコード: 書き込みエラー */
  200. define('E_APP_WRITE'38);
  201.  
  202. /** エラーコード: CSV分割エラー(行継続) */
  203. define('E_UTIL_CSV_CONTINUE'64);
  204.  
  205. /** エラーコード: フォーム値型エラー(スカラー引数に配列指定) */
  206. define('E_FORM_WRONGTYPE_SCALAR'128);
  207.  
  208. /** エラーコード: フォーム値型エラー(配列引数にスカラー指定) */
  209. define('E_FORM_WRONGTYPE_ARRAY'129);
  210.  
  211. /** エラーコード: フォーム値型エラー(整数型) */
  212. define('E_FORM_WRONGTYPE_INT'130);
  213.  
  214. /** エラーコード: フォーム値型エラー(浮動小数点数型) */
  215. define('E_FORM_WRONGTYPE_FLOAT'131);
  216.  
  217. /** エラーコード: フォーム値型エラー(日付型) */
  218. define('E_FORM_WRONGTYPE_DATETIME'132);
  219.  
  220. /** エラーコード: フォーム値型エラー(BOOL型) */
  221. define('E_FORM_WRONGTYPE_BOOLEAN'133);
  222.  
  223. /** エラーコード: フォーム値型エラー(FILE型) */
  224. define('E_FORM_WRONGTYPE_FILE'134);
  225.  
  226. /** エラーコード: フォーム値必須エラー */
  227. define('E_FORM_REQUIRED'135);
  228.  
  229. /** エラーコード: フォーム値最小値エラー(整数型) */
  230. define('E_FORM_MIN_INT'136);
  231.  
  232. /** エラーコード: フォーム値最小値エラー(浮動小数点数型) */
  233. define('E_FORM_MIN_FLOAT'137);
  234.  
  235. /** エラーコード: フォーム値最小値エラー(文字列型) */
  236. define('E_FORM_MIN_STRING'138);
  237.  
  238. /** エラーコード: フォーム値最小値エラー(日付型) */
  239. define('E_FORM_MIN_DATETIME'139);
  240.  
  241. /** エラーコード: フォーム値最小値エラー(ファイル型) */
  242. define('E_FORM_MIN_FILE'140);
  243.  
  244. /** エラーコード: フォーム値最大値エラー(整数型) */
  245. define('E_FORM_MAX_INT'141);
  246.  
  247. /** エラーコード: フォーム値最大値エラー(浮動小数点数型) */
  248. define('E_FORM_MAX_FLOAT'142);
  249.  
  250. /** エラーコード: フォーム値最大値エラー(文字列型) */
  251. define('E_FORM_MAX_STRING'143);
  252.  
  253. /** エラーコード: フォーム値最大値エラー(日付型) */
  254. define('E_FORM_MAX_DATETIME'144);
  255.  
  256. /** エラーコード: フォーム値最大値エラー(ファイル型) */
  257. define('E_FORM_MAX_FILE'145);
  258.  
  259. /** エラーコード: フォーム値文字種(正規表現)エラー */
  260. define('E_FORM_REGEXP'146);
  261.  
  262. /** エラーコード: フォーム値数値(カスタムチェック)エラー */
  263. define('E_FORM_INVALIDVALUE'147);
  264.  
  265. /** エラーコード: フォーム値文字種(カスタムチェック)エラー */
  266. define('E_FORM_INVALIDCHAR'148);
  267.  
  268. /** エラーコード: 確認用エントリ入力エラー */
  269. define('E_FORM_CONFIRM'149);
  270.  
  271. /** エラーコード: キャッシュタイプ不正 */
  272. define('E_CACHE_INVALID_TYPE'192);
  273.  
  274. /** エラーコード: キャッシュ値なし */
  275. define('E_CACHE_NO_VALUE'193);
  276.  
  277. /** エラーコード: キャッシュ有効期限 */
  278. define('E_CACHE_EXPIRED'194);
  279.  
  280. /** エラーコード: キャッシュエラー(その他) */
  281. define('E_CACHE_GENERAL'195);
  282.  
  283. /** エラーコード: プラグインが見つからない */
  284. define('E_PLUGIN_NOTFOUND'196);
  285.  
  286. /** エラーコード: プラグインエラー(その他) */
  287. define('E_PLUGIN_GENERAL'197);
  288.  
  289. if (defined('E_STRICT'== false{
  290.     /** PHP 5との互換保持定義 */
  291.     define('E_STRICT'2048);
  292. }
  293.  
  294. /** Ethnaグローバル変数: エラーコールバック関数 */
  295. $GLOBALS['_Ethna_error_callback_list'array();
  296.  
  297. /** Ethnaグローバル変数: エラーメッセージ */
  298. $GLOBALS['_Ethna_error_message_list'array();
  299.  
  300.  
  301. // {{{ Ethna
  302. /**
  303.  *  Ethnaフレームワーククラス
  304.  *
  305.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  306.  *  @access     public
  307.  *  @package    Ethna
  308.  */
  309. class Ethna extends PEAR
  310. {
  311.     /**#@+
  312.      *  @access private
  313.      */
  314.  
  315.     /**#@-*/
  316.  
  317.     /**
  318.      *  Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_ERROR)
  319.      *
  320.      *  @access public
  321.      *  @param  string  $message            エラーメッセージ
  322.      *  @param  int     $code               エラーコード
  323.      *  @static
  324.      */
  325.     function &raiseError($message$code E_GENERAL)
  326.     {
  327.         $userinfo null;
  328.         if (func_num_args(2{
  329.             $userinfo array_slice(func_get_args()2);
  330.             if (count($userinfo== && is_array($userinfo[0])) {
  331.                 $userinfo $userinfo[0];
  332.             }
  333.         }
  334.         return PEAR::raiseError($message$codePEAR_ERROR_RETURNE_USER_ERROR$userinfo'Ethna_Error');
  335.     }
  336.  
  337.     /**
  338.      *  Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_WARNING)
  339.      *
  340.      *  @access public
  341.      *  @param  string  $message            エラーメッセージ
  342.      *  @param  int     $code               エラーコード
  343.      *  @static
  344.      */
  345.     function &raiseWarning($message$code E_GENERAL)
  346.     {
  347.         $userinfo null;
  348.         if (func_num_args(2{
  349.             $userinfo array_slice(func_get_args()2);
  350.             if (count($userinfo== && is_array($userinfo[0])) {
  351.                 $userinfo $userinfo[0];
  352.             }
  353.         }
  354.         return PEAR::raiseError($message$codePEAR_ERROR_RETURNE_USER_WARNING$userinfo'Ethna_Error');
  355.     }
  356.  
  357.     /**
  358.      *  Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_NOTICE)
  359.      *
  360.      *  @access public
  361.      *  @param  string  $message            エラーメッセージ
  362.      *  @param  int     $code               エラーコード
  363.      *  @static
  364.      */
  365.     function &raiseNotice($message$code E_GENERAL)
  366.     {
  367.         $userinfo null;
  368.         if (func_num_args(2{
  369.             $userinfo array_slice(func_get_args()2);
  370.             if (count($userinfo== && is_array($userinfo[0])) {
  371.                 $userinfo $userinfo[0];
  372.             }
  373.         }
  374.         return PEAR::raiseError($message$codePEAR_ERROR_RETURNE_USER_NOTICE$userinfo'Ethna_Error');
  375.     }
  376.  
  377.     /**
  378.      *  エラー発生時の(フレームワークとしての)コールバック関数を設定する
  379.      *
  380.      *  @access public
  381.      *  @param  mixed   string:コールバック関数名 array:コールバッククラス(名|オブジェクト)+メソッド名
  382.      *  @static
  383.      */
  384.     function setErrorCallback($callback)
  385.     {
  386.         $GLOBALS['_Ethna_error_callback_list'][$callback;
  387.     }
  388.  
  389.     /**
  390.      *  エラー発生時の(フレームワークとしての)コールバック関数をクリアする
  391.      *
  392.      *  @access public
  393.      *  @static
  394.      */
  395.     function clearErrorCallback()
  396.     {
  397.         $GLOBALS['_Ethna_error_callback_list'array();
  398.     }
  399.  
  400.     /**
  401.      *  エラー発生時の処理を行う(コールバック関数/メソッドを呼び出す)
  402.      *  
  403.      *  @access public
  404.      *  @param  object  Ethna_Error     Ethna_Errorオブジェクト
  405.      *  @static
  406.      */
  407.     function handleError(&$error)
  408.     {
  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];
  416.  
  417.                 // perform some more checks?
  418.                 $object->$method($error);
  419.             else {
  420.                 call_user_func($callback$error);
  421.             }
  422.         }
  423.     }
  424. }
  425. // }}}
  426. ?>

Documentation generated on Thu, 08 May 2008 00:14:16 +0900 by phpDocumentor 1.4.2