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$
  10.  */
  11.  
  12. //
  13. //  PEAR OS_WINDOWS constant replacement.
  14. //
  15. //  PEAR の OS_WINDOWS 定数は、defined関数で
  16. //  既に定義されているかをチェックしていない。
  17. //  よって require_once 'PEAR.php' とすると
  18. //  E_NOTICEが出ることから、Windows環境判定用
  19. //  として独自の定数を定義する
  20. //
  21. if (substr(PHP_OS03== 'WIN'
  22.  && !defined('ETHNA_OS_WINDOWS')) {
  23.     define('ETHNA_OS_WINDOWS'true);
  24. elseif (!defined('ETHNA_OS_WINDOWS')) {
  25.     define('ETHNA_OS_WINDOWS'false);
  26. }
  27. //  PHP 5.1.0 以降向けの変更
  28. //  date.timezone が設定されていないと
  29. //  E_STRICT|WARNING が発生する
  30. if (!ini_get('date.timezone')) {
  31.     ini_set('date.timezone''Asia/Tokyo');
  32. }
  33.  
  34. if (!defined('PATH_SEPARATOR')) {
  35.     if (ETHNA_OS_WINDOWS{
  36.         /** include_path separator(Windows) */
  37.         define('PATH_SEPARATOR'';');
  38.     else {
  39.         /** include_path separator(Unix) */
  40.         define('PATH_SEPARATOR'':');
  41.     }
  42. }
  43. if (!defined('DIRECTORY_SEPARATOR')) {
  44.     if (ETHNA_OS_WINDOWS{
  45.         /** directory separator(Windows) */
  46.         define('DIRECTORY_SEPARATOR''\\');
  47.     else {
  48.         /** separator(Unix) */
  49.         define('DIRECTORY_SEPARATOR''/');
  50.     }
  51. }
  52.  
  53. /** バージョン定義 */
  54. define('ETHNA_VERSION''2.5.0');
  55.  
  56. /**
  57.  * ダミーのエラーモード
  58.  * PEAR非依存、かつ互換性を維持するためのもの
  59.  */
  60. define('ETHNA_ERROR_DUMMY''dummy');
  61.  
  62. /** Ethnaベースディレクトリ定義 */
  63. define('ETHNA_BASE'dirname(__FILE__));
  64.  
  65. require_once ETHNA_BASE '/class/Ethna_ActionClass.php';
  66. require_once ETHNA_BASE '/class/Ethna_ActionError.php';
  67. require_once ETHNA_BASE '/class/Ethna_ActionForm.php';
  68. require_once ETHNA_BASE '/class/Ethna_AppManager.php';
  69. require_once ETHNA_BASE '/class/Ethna_AppObject.php';
  70. require_once ETHNA_BASE '/class/Ethna_AppSQL.php';
  71. require_once ETHNA_BASE '/class/Ethna_AppSearchObject.php';
  72. require_once ETHNA_BASE '/class/Ethna_Backend.php';
  73. require_once ETHNA_BASE '/class/Ethna_CacheManager.php';
  74. require_once ETHNA_BASE '/class/Ethna_Config.php';
  75. require_once ETHNA_BASE '/class/Ethna_Controller.php';
  76. require_once ETHNA_BASE '/class/Ethna_ClassFactory.php';
  77. require_once ETHNA_BASE '/class/Ethna_DB.php';
  78. require_once ETHNA_BASE '/class/Ethna_Error.php';
  79. require_once ETHNA_BASE '/class/Ethna_Filter.php';
  80. require_once ETHNA_BASE '/class/Ethna_Handle.php';
  81. require_once ETHNA_BASE '/class/Ethna_I18N.php';
  82. require_once ETHNA_BASE '/class/Ethna_Logger.php';
  83. require_once ETHNA_BASE '/class/Ethna_MailSender.php';
  84. require_once ETHNA_BASE '/class/Ethna_Session.php';
  85. require_once ETHNA_BASE '/class/Ethna_Generator.php';
  86. require_once ETHNA_BASE '/class/Ethna_UrlHandler.php';
  87. require_once ETHNA_BASE '/class/Ethna_Util.php';
  88. require_once ETHNA_BASE '/class/Ethna_ViewClass.php';
  89. require_once ETHNA_BASE '/class/View/Ethna_View_List.php';
  90. require_once ETHNA_BASE '/class/Ethna_Plugin.php';
  91. require_once ETHNA_BASE '/class/Ethna_Renderer.php';
  92. require_once ETHNA_BASE '/class/CLI/Ethna_CLI_ActionClass.php';
  93.  
  94. if (extension_loaded('soap')) {
  95.     require_once ETHNA_BASE '/class/SOAP/Ethna_SOAP_ActionForm.php';
  96.     require_once ETHNA_BASE '/class/SOAP/Ethna_SOAP_Gateway.php';
  97.     require_once ETHNA_BASE '/class/SOAP/Ethna_SOAP_GatewayGenerator.php';
  98.     require_once ETHNA_BASE '/class/SOAP/Ethna_SOAP_Util.php';
  99.     require_once ETHNA_BASE '/class/SOAP/Ethna_SOAP_WsdlGenerator.php';
  100. }
  101.  
  102. /** ゲートウェイ: WWW */
  103. define('GATEWAY_WWW'1);
  104.  
  105. /** ゲートウェイ: CLI */
  106. define('GATEWAY_CLI'2);
  107.  
  108. /** ゲートウェイ: XMLRPC */
  109. define('GATEWAY_XMLRPC'3);
  110.  
  111. /** ゲートウェイ: SOAP */
  112. define('GATEWAY_SOAP'4);
  113.  
  114.  
  115. /** DB種別定義: R/W */
  116. define('DB_TYPE_RW'1);
  117.  
  118. /** DB種別定義: R/O */
  119. define('DB_TYPE_RO'2);
  120.  
  121. /** DB種別定義: Misc  */
  122. define('DB_TYPE_MISC'3);
  123.  
  124.  
  125. /** 要素型: 整数 */
  126. define('VAR_TYPE_INT'1);
  127.  
  128. /** 要素型: 浮動小数点数 */
  129. define('VAR_TYPE_FLOAT'2);
  130.  
  131. /** 要素型: 文字列 */
  132. define('VAR_TYPE_STRING'3);
  133.  
  134. /** 要素型: 日付 */
  135. define('VAR_TYPE_DATETIME'4);
  136.  
  137. /** 要素型: 真偽値 */
  138. define('VAR_TYPE_BOOLEAN'5);
  139.  
  140. /** 要素型: ファイル */
  141. define('VAR_TYPE_FILE'6);
  142.  
  143.  
  144. /** フォーム型: text */
  145. define('FORM_TYPE_TEXT'1);
  146.  
  147. /** フォーム型: password */
  148. define('FORM_TYPE_PASSWORD'2);
  149.  
  150. /** フォーム型: textarea */
  151. define('FORM_TYPE_TEXTAREA'3);
  152.  
  153. /** フォーム型: select */
  154. define('FORM_TYPE_SELECT'4);
  155.  
  156. /** フォーム型: radio */
  157. define('FORM_TYPE_RADIO'5);
  158.  
  159. /** フォーム型: checkbox */
  160. define('FORM_TYPE_CHECKBOX'6);
  161.  
  162. /** フォーム型: button */
  163. define('FORM_TYPE_SUBMIT'7);
  164.  
  165. /** フォーム型: file */
  166. define('FORM_TYPE_FILE'8);
  167.  
  168. /** フォーム型: button */
  169. define('FORM_TYPE_BUTTON'9);
  170.  
  171. /** フォーム型: hidden */
  172. define('FORM_TYPE_HIDDEN'10);
  173.  
  174.  
  175. /** エラーコード: 一般エラー */
  176. define('E_GENERAL'1);
  177.  
  178. /** エラーコード: DB接続エラー */
  179. define('E_DB_CONNECT'2);
  180.  
  181. /** エラーコード: DB設定なし */
  182. define('E_DB_NODSN'3);
  183.  
  184. /** エラーコード: DBクエリエラー */
  185. define('E_DB_QUERY'4);
  186.  
  187. /** エラーコード: DBユニークキーエラー */
  188. define('E_DB_DUPENT'5);
  189.  
  190. /** エラーコード: DB種別エラー */
  191. define('E_DB_INVALIDTYPE'6);
  192.  
  193. /** エラーコード: セッションエラー(有効期限切れ) */
  194. define('E_SESSION_EXPIRE'16);
  195.  
  196. /** エラーコード: セッションエラー(IPアドレスチェックエラー) */
  197. define('E_SESSION_IPCHECK'17);
  198.  
  199. /** エラーコード: アクション未定義エラー */
  200. define('E_APP_UNDEFINED_ACTION'32);
  201.  
  202. /** エラーコード: アクションクラス未定義エラー */
  203. define('E_APP_UNDEFINED_ACTIONCLASS'33);
  204.  
  205. /** エラーコード: アプリケーションオブジェクトID重複エラー */
  206. define('E_APP_DUPENT'34);
  207.  
  208. /** エラーコード: アプリケーションメソッドが存在しない */
  209. define('E_APP_NOMETHOD'35);
  210.  
  211. /** エラーコード: ロックエラー */
  212. define('E_APP_LOCK'36);
  213.  
  214. /** エラーコード: 読み込みエラー */
  215. define('E_APP_READ'37);
  216.  
  217. /** エラーコード: 書き込みエラー */
  218. define('E_APP_WRITE'38);
  219.  
  220. /** エラーコード: CSV分割エラー(行継続) */
  221. define('E_UTIL_CSV_CONTINUE'64);
  222.  
  223. /** エラーコード: フォーム値型エラー(スカラー引数に配列指定) */
  224. define('E_FORM_WRONGTYPE_SCALAR'128);
  225.  
  226. /** エラーコード: フォーム値型エラー(配列引数にスカラー指定) */
  227. define('E_FORM_WRONGTYPE_ARRAY'129);
  228.  
  229. /** エラーコード: フォーム値型エラー(整数型) */
  230. define('E_FORM_WRONGTYPE_INT'130);
  231.  
  232. /** エラーコード: フォーム値型エラー(浮動小数点数型) */
  233. define('E_FORM_WRONGTYPE_FLOAT'131);
  234.  
  235. /** エラーコード: フォーム値型エラー(日付型) */
  236. define('E_FORM_WRONGTYPE_DATETIME'132);
  237.  
  238. /** エラーコード: フォーム値型エラー(BOOL型) */
  239. define('E_FORM_WRONGTYPE_BOOLEAN'133);
  240.  
  241. /** エラーコード: フォーム値型エラー(FILE型) */
  242. define('E_FORM_WRONGTYPE_FILE'134);
  243.  
  244. /** エラーコード: フォーム値必須エラー */
  245. define('E_FORM_REQUIRED'135);
  246.  
  247. /** エラーコード: フォーム値最小値エラー(整数型) */
  248. define('E_FORM_MIN_INT'136);
  249.  
  250. /** エラーコード: フォーム値最小値エラー(浮動小数点数型) */
  251. define('E_FORM_MIN_FLOAT'137);
  252.  
  253. /** エラーコード: フォーム値最小値エラー(文字列型) */
  254. define('E_FORM_MIN_STRING'138);
  255.  
  256. /** エラーコード: フォーム値最小値エラー(日付型) */
  257. define('E_FORM_MIN_DATETIME'139);
  258.  
  259. /** エラーコード: フォーム値最小値エラー(ファイル型) */
  260. define('E_FORM_MIN_FILE'140);
  261.  
  262. /** エラーコード: フォーム値最大値エラー(整数型) */
  263. define('E_FORM_MAX_INT'141);
  264.  
  265. /** エラーコード: フォーム値最大値エラー(浮動小数点数型) */
  266. define('E_FORM_MAX_FLOAT'142);
  267.  
  268. /** エラーコード: フォーム値最大値エラー(文字列型) */
  269. define('E_FORM_MAX_STRING'143);
  270.  
  271. /** エラーコード: フォーム値最大値エラー(日付型) */
  272. define('E_FORM_MAX_DATETIME'144);
  273.  
  274. /** エラーコード: フォーム値最大値エラー(ファイル型) */
  275. define('E_FORM_MAX_FILE'145);
  276.  
  277. /** エラーコード: フォーム値文字種(正規表現)エラー */
  278. define('E_FORM_REGEXP'146);
  279.  
  280. /** エラーコード: フォーム値数値(カスタムチェック)エラー */
  281. define('E_FORM_INVALIDVALUE'147);
  282.  
  283. /** エラーコード: フォーム値文字種(カスタムチェック)エラー */
  284. define('E_FORM_INVALIDCHAR'148);
  285.  
  286. /** エラーコード: 確認用エントリ入力エラー */
  287. define('E_FORM_CONFIRM'149);
  288.  
  289. /** エラーコード: キャッシュタイプ不正 */
  290. define('E_CACHE_INVALID_TYPE'192);
  291.  
  292. /** エラーコード: キャッシュ値なし */
  293. define('E_CACHE_NO_VALUE'193);
  294.  
  295. /** エラーコード: キャッシュ有効期限 */
  296. define('E_CACHE_EXPIRED'194);
  297.  
  298. /** エラーコード: キャッシュエラー(その他) */
  299. define('E_CACHE_GENERAL'195);
  300.  
  301. /** エラーコード: プラグインが見つからない */
  302. define('E_PLUGIN_NOTFOUND'196);
  303.  
  304. /** エラーコード: プラグインエラー(その他) */
  305. define('E_PLUGIN_GENERAL'197);
  306.  
  307. /** PHP 5との互換保持定義 */
  308. if (defined('E_STRICT'== false{
  309.     define('E_STRICT'2048);
  310. }
  311. if (defined('E_DEPRECATED'== false{
  312.     define('E_DEPRECATED'8192);
  313. }
  314.  
  315. /** Ethnaグローバル変数: エラーコールバック関数 */
  316. $GLOBALS['_Ethna_error_callback_list'array();
  317.  
  318. /** Ethnaグローバル変数: エラーメッセージ */
  319. $GLOBALS['_Ethna_error_message_list'array();
  320.  
  321.  
  322. // {{{ Ethna
  323. /**
  324.  *  Ethnaフレームワーククラス
  325.  *
  326.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  327.  *  @access     public
  328.  *  @package    Ethna
  329.  */
  330. class Ethna
  331. {
  332.     /**
  333.      *  渡されたオブジェクトが Ethna_Error オブジェクト
  334.      *  またはそのサブクラスのオブジェクトかどうかチェックします。
  335.      *
  336.      *  @param mixed  $data    チェックする変数
  337.      *  @param mixed  $msgcode チェックするエラーメッセージまたはエラーコード
  338.      *  @return mixed 変数が、Ethna_Error の場合に TRUEを返します。
  339.      *                 第2引数が設定された場合は、さらに 所与された $msgcode
  340.      *                 を含む場合のみ TRUEを返します。
  341.      *  @static
  342.      */
  343.     function isError($data$msgcode NULL)
  344.     {
  345.         if (!is_object($data)) {
  346.             return false;
  347.         }
  348.  
  349.         $class_name get_class($data);
  350.         if (strcasecmp($class_name'Ethna_Error'=== 0
  351.          || is_subclass_of($data'Ethna_Error')) {
  352.             if ($msgcode == NULL{
  353.                 return true;
  354.             elseif ($data->getCode(== $msgcode{
  355.                 return true;
  356.             }
  357.         }
  358.  
  359.         return false;
  360.     }
  361.  
  362.     /**
  363.      *  Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_ERROR)
  364.      *
  365.      *  @access public
  366.      *  @param  string  $message            エラーメッセージ
  367.      *  @param  int     $code               エラーコード
  368.      *  @static
  369.      */
  370.     function &raiseError($message$code E_GENERAL)
  371.     {
  372.         $userinfo null;
  373.         if (func_num_args(2{
  374.             $userinfo array_slice(func_get_args()2);
  375.             if (count($userinfo== && is_array($userinfo[0])) {
  376.                 $userinfo $userinfo[0];
  377.             }
  378.         }
  379.         $error new Ethna_Error($message$codeETHNA_ERROR_DUMMYE_USER_ERROR$userinfo'Ethna_Error');
  380.         return $error;
  381.     }
  382.  
  383.     /**
  384.      *  Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_WARNING)
  385.      *
  386.      *  @access public
  387.      *  @param  string  $message            エラーメッセージ
  388.      *  @param  int     $code               エラーコード
  389.      *  @static
  390.      */
  391.     function &raiseWarning($message$code E_GENERAL)
  392.     {
  393.         $userinfo null;
  394.         if (func_num_args(2{
  395.             $userinfo array_slice(func_get_args()2);
  396.             if (count($userinfo== && is_array($userinfo[0])) {
  397.                 $userinfo $userinfo[0];
  398.             }
  399.         }
  400.  
  401.         $error new Ethna_Error($message$codeETHNA_ERROR_DUMMYE_USER_WARNING$userinfo'Ethna_Error');
  402.         return $error;
  403.     }
  404.  
  405.     /**
  406.      *  Ethna_Errorオブジェクトを生成する(エラーレベル:E_USER_NOTICE)
  407.      *
  408.      *  @access public
  409.      *  @param  string  $message            エラーメッセージ
  410.      *  @param  int     $code               エラーコード
  411.      *  @static
  412.      */
  413.     function &raiseNotice($message$code E_GENERAL)
  414.     {
  415.         $userinfo null;
  416.         if (func_num_args(2{
  417.             $userinfo array_slice(func_get_args()2);
  418.             if (count($userinfo== && is_array($userinfo[0])) {
  419.                 $userinfo $userinfo[0];
  420.             }
  421.         }
  422.  
  423.         $error new Ethna_Error($message$codeETHNA_ERROR_DUMMYE_USER_NOTICE$userinfo'Ethna_Error');
  424.         return $error;
  425.     }
  426.  
  427.     /**
  428.      *  エラー発生時の(フレームワークとしての)コールバック関数を設定する
  429.      *
  430.      *  @access public
  431.      *  @param  mixed   string:コールバック関数名 array:コールバッククラス(名|オブジェクト)+メソッド名
  432.      *  @static
  433.      */
  434.     function setErrorCallback($callback)
  435.     {
  436.         $GLOBALS['_Ethna_error_callback_list'][$callback;
  437.     }
  438.  
  439.     /**
  440.      *  エラー発生時の(フレームワークとしての)コールバック関数をクリアする
  441.      *
  442.      *  @access public
  443.      *  @static
  444.      */
  445.     function clearErrorCallback()
  446.     {
  447.         $GLOBALS['_Ethna_error_callback_list'array();
  448.     }
  449.  
  450.     /**
  451.      *  エラー発生時の処理を行う(コールバック関数/メソッドを呼び出す)
  452.      *  
  453.      *  @access public
  454.      *  @param  object  Ethna_Error     Ethna_Errorオブジェクト
  455.      *  @static
  456.      */
  457.     function handleError(&$error)
  458.     {
  459.         for ($i 0$i count($GLOBALS['_Ethna_error_callback_list'])$i++{
  460.             $callback =$GLOBALS['_Ethna_error_callback_list'][$i];
  461.             if (is_array($callback== false{
  462.                 call_user_func($callback$error);
  463.             else if (is_object($callback[0])) {
  464.                 $object =$callback[0];
  465.                 $method $callback[1];
  466.  
  467.                 // perform some more checks?
  468.                 $object->$method($error);
  469.             else {  
  470.                 //  call statically
  471.                 call_user_func($callback$error);
  472.             }
  473.         }
  474.     }
  475. }
  476. // }}}
  477.  
  478. ?>

Documentation generated on Fri, 11 Nov 2011 03:58:56 +0900 by phpDocumentor 1.4.3