Source for file Ethna_Controller.php

Documentation is available at Ethna_Controller.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Controller.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_Controller.php 516 2008-04-30 16:30:05Z mumumu-org $
  10.  */
  11.  
  12. // {{{ Ethna_Controller
  13. /**
  14.  *  コントローラクラス
  15.  *
  16.  *  @todo       gatewayでswitchしてるところがダサダサ
  17.  *
  18.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  19.  *  @access     public
  20.  *  @package    Ethna
  21.  */
  22. {
  23.     /**#@+
  24.      *  @access private
  25.      */
  26.  
  27.     /** @var    string      アプリケーションID */
  28.     var $appid 'ETHNA';
  29.  
  30.     /** @var    string      アプリケーションベースディレクトリ */
  31.     var $base '';
  32.  
  33.     /** @var    string      アプリケーションベースURL */
  34.     var $url '';
  35.  
  36.     /** @var    string      アプリケーションDSN(Data Source Name) */
  37.     var $dsn;
  38.  
  39.     /** @var    array       アプリケーションディレクトリ */
  40.     var $directory array();
  41.  
  42.     /** @var    array       アプリケーションディレクトリ(デフォルト) */
  43.     var $directory_default array(
  44.         'action'        => 'app/action',
  45.         'action_cli'    => 'app/action_cli',
  46.         'action_xmlrpc' => 'app/action_xmlrpc',
  47.         'app'           => 'app',
  48.         'plugin'        => 'app/plugin',
  49.         'bin'           => 'bin',
  50.         'etc'           => 'etc',
  51.         'filter'        => 'app/filter',
  52.         'locale'        => 'locale',
  53.         'log'           => 'log',
  54.         'plugins'       => array(),
  55.         'template'      => 'template',
  56.         'template_c'    => 'tmp',
  57.         'tmp'           => 'tmp',
  58.         'view'          => 'app/view',
  59.         'www'           => 'www',
  60.         'test'          => 'app/test',
  61.     );
  62.  
  63.     /** @var    array       DBアクセス定義 */
  64.     var $db array(
  65.         ''              => DB_TYPE_RW,
  66.     );
  67.  
  68.     /** @var    array       拡張子設定 */
  69.     var $ext array(
  70.         'php'           => 'php',
  71.         'tpl'           => 'tpl',
  72.     );
  73.  
  74.     /** @var    array       クラス設定 */
  75.     var $class array();
  76.  
  77.     /** @var    array       クラス設定(デフォルト) */
  78.     var $class_default array(
  79.         'class'         => 'Ethna_ClassFactory',
  80.         'backend'       => 'Ethna_Backend',
  81.         'config'        => 'Ethna_Config',
  82.         'db'            => 'Ethna_DB',
  83.         'error'         => 'Ethna_ActionError',
  84.         'form'          => 'Ethna_ActionForm',
  85.         'i18n'          => 'Ethna_I18N',
  86.         'logger'        => 'Ethna_Logger',
  87.         'plugin'        => 'Ethna_Plugin',
  88.         'renderer'      => 'Ethna_Renderer_Smarty',
  89.         'session'       => 'Ethna_Session',
  90.         'sql'           => 'Ethna_AppSQL',
  91.         'view'          => 'Ethna_ViewClass',
  92.         'url_handler'   => 'Ethna_UrlHandler',
  93.     );
  94.  
  95.     /** @var    array       検索対象となるプラグインのアプリケーションIDのリスト */
  96.     var $plugin_search_appids;
  97.  
  98.     /** @var    array       フィルタ設定 */
  99.     var $filter array(
  100.     );
  101.  
  102.     /** @var    string      使用言語設定 */
  103.     var $language;
  104.  
  105.     /** @var    string      システム側エンコーディング */
  106.     var $system_encoding;
  107.  
  108.     /** @var    string      クライアント側エンコーディング */
  109.     var $client_encoding;
  110.  
  111.     /** @var    string  現在実行中のアクション名 */
  112.     var $action_name;
  113.  
  114.     /** @var    string  現在実行中のXMLRPCメソッド名 */
  115.     var $xmlrpc_method_name;
  116.  
  117.     /** @var    array   forward定義 */
  118.     var $forward array();
  119.  
  120.     /** @var    array   action定義 */
  121.     var $action array();
  122.  
  123.     /** @var    array   action(CLI)定義 */
  124.     var $action_cli array();
  125.  
  126.     /** @var    array   action(XMLRPC)定義 */
  127.     var $action_xmlrpc array();
  128.  
  129.     /** @var    array   アプリケーションマネージャ定義 */
  130.     var $manager array();
  131.  
  132.     /** @var    object  レンダラー */
  133.     var $renderer null;
  134.  
  135.     /** @var    array   smarty modifier定義 */
  136.     var $smarty_modifier_plugin array();
  137.  
  138.     /** @var    array   smarty function定義 */
  139.     var $smarty_function_plugin array();
  140.  
  141.     /** @var    array   smarty block定義 */
  142.     var $smarty_block_plugin array();
  143.  
  144.     /** @var    array   smarty prefilter定義 */
  145.     var $smarty_prefilter_plugin array();
  146.  
  147.     /** @var    array   smarty postfilter定義 */
  148.     var $smarty_postfilter_plugin array();
  149.  
  150.     /** @var    array   smarty outputfilter定義 */
  151.     var $smarty_outputfilter_plugin array();
  152.  
  153.  
  154.     /** @var    array   フィルターチェイン(Ethna_Filterオブジェクトの配列) */
  155.     var $filter_chain array();
  156.  
  157.     /** @var    object  Ethna_ClassFactory  クラスファクトリオブジェクト */
  158.     var $class_factory null;
  159.  
  160.     /** @var    object  Ethna_ActionForm    フォームオブジェクト */
  161.     var $action_form null;
  162.  
  163.     /** @var    object  Ethna_View          ビューオブジェクト */
  164.     var $view null;
  165.  
  166.     /** @var    object  Ethna_Config        設定オブジェクト */
  167.     var $config null;
  168.  
  169.     /** @var    object  Ethna_Logger        ログオブジェクト */
  170.     var $logger null;
  171.  
  172.     /** @var    object  Ethna_Plugin        プラグインオブジェクト */
  173.     var $plugin null;
  174.  
  175.     /** @var    string  リクエストのゲートウェイ(www/cli/rest/xmlrpc/soap...) */
  176.     var $gateway GATEWAY_WWW;
  177.  
  178.     /**#@-*/
  179.  
  180.  
  181.     /**
  182.      *  Ethna_Controllerクラスのコンストラクタ
  183.      *
  184.      *  @access     public
  185.      */
  186.     function Ethna_Controller($gateway GATEWAY_WWW)
  187.     {
  188.         $GLOBALS['_Ethna_controller'=$this;
  189.         if ($this->base === ""{
  190.             // EthnaコマンドなどでBASEが定義されていない場合がある
  191.             if (defined('BASE')) {
  192.                 $this->base BASE;
  193.             }
  194.         }
  195.  
  196.         $this->gateway $gateway;
  197.  
  198.         // クラス設定の未定義値を補完
  199.         foreach ($this->class_default as $key => $val{
  200.             if (isset($this->class[$key]== false{
  201.                 $this->class[$key$val;
  202.             }
  203.         }
  204.  
  205.         // ディレクトリ設定の未定義値を補完
  206.         foreach ($this->directory_default as $key => $val{
  207.             if (isset($this->directory[$key]== false{
  208.                 $this->directory[$key$val;
  209.             }
  210.         }
  211.  
  212.         // クラスファクトリオブジェクトの生成
  213.         $class_factory $this->class['class'];
  214.         $this->class_factory =new $class_factory($this$this->class);
  215.  
  216.         // エラーハンドラの設定
  217.         Ethna::setErrorCallback(array(&$this'handleError'));
  218.  
  219.         // ディレクトリ名の設定(相対パス->絶対パス)
  220.         foreach ($this->directory as $key => $value{
  221.             if ($key == 'plugins'{
  222.                 // Smartyプラグインディレクトリは配列で指定する
  223.                 $tmp array();
  224.                 foreach (to_array($valueas $elt{
  225.                     if (Ethna_Util::isAbsolute($elt== false{
  226.                         $tmp[$this->base (empty($this->base'' '/'$elt;
  227.                     }
  228.                 }
  229.                 $this->directory[$key$tmp;
  230.             else {
  231.                 if (Ethna_Util::isAbsolute($value== false{
  232.                     $this->directory[$key$this->base (empty($this->base'' '/'$value;
  233.                 }
  234.             }
  235.         }
  236.  
  237.         // 初期設定
  238.         list($this->language$this->system_encoding$this->client_encoding$this->_getDefaultLanguage();
  239.  
  240.         $this->config =$this->getConfig();
  241.         $this->dsn $this->_prepareDSN();
  242.         $this->url $this->config->get('url');
  243.  
  244.         // プラグインオブジェクトの用意
  245.         $this->plugin =$this->getPlugin();
  246.  
  247.         //// assert (experimental)
  248.         //if ($this->config->get('debug') === false) {
  249.         //    ini_set('assert.active', 0);
  250.         //}
  251.  
  252.         // ログ出力開始
  253.         $this->logger =$this->getLogger();
  254.         $this->plugin->setLogger($this->logger);
  255.         $this->logger->begin();
  256.  
  257.         // Ethnaマネージャ設定
  258.         $this->_activateEthnaManager();
  259.     }
  260.  
  261.     /**
  262.      *  (現在アクティブな)コントローラのインスタンスを返す
  263.      *
  264.      *  @access public
  265.      *  @return object  Ethna_Controller    コントローラのインスタンス
  266.      *  @static
  267.      */
  268.     function &getInstance()
  269.     {
  270.         if (isset($GLOBALS['_Ethna_controller'])) {
  271.             return $GLOBALS['_Ethna_controller'];
  272.         else {
  273.             $_ret_object null;
  274.             return $_ret_object;
  275.         }
  276.     }
  277.  
  278.     /**
  279.      *  アプリケーションIDを返す
  280.      *
  281.      *  @access public
  282.      *  @return string  アプリケーションID
  283.      */
  284.     function getAppId()
  285.     {
  286.         return ucfirst(strtolower($this->appid));
  287.     }
  288.  
  289.     /**
  290.      *  アプリケーションIDをチェックする
  291.      *
  292.      *  @access public
  293.      *  @param  string  $id     アプリケーションID
  294.      *  @return mixed   true:OK Ethna_Error:NG
  295.      *  @static
  296.      */
  297.     function &checkAppId($id)
  298.     {
  299.         $true true;
  300.         if (strcasecmp($id'ethna'=== 0
  301.             || strcasecmp($id'app'=== 0{
  302.             return Ethna::raiseError("Application Id [$id] is reserved\n");
  303.         }
  304.         if (preg_match('/^[0-9a-zA-Z]+$/'$id=== 0{
  305.             return Ethna::raiseError(
  306.                 "Only Numeric(0-9) and Alphabetical(A-Z) is allowed for Application Id\n"
  307.             );
  308.         }
  309.         return $true;
  310.     }
  311.  
  312.     /**
  313.      *  アクション名をチェックする
  314.      *
  315.      *  @access public
  316.      *  @param  string  $action_name    アクション名
  317.      *  @return mixed   true:OK Ethna_Error:NG
  318.      *  @static
  319.      */
  320.     function &checkActionName($action_name)
  321.     {
  322.         $true true;
  323.         if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
  324.                        $action_name=== 0{
  325.             return Ethna::raiseError("invalid action name [$action_name]");
  326.         }
  327.         return $true;
  328.     }
  329.  
  330.     /**
  331.      *  ビュー名をチェックする
  332.      *
  333.      *  @access public
  334.      *  @param  string  $view_name    ビュー名
  335.      *  @return mixed   true:OK Ethna_Error:NG
  336.      *  @static
  337.      */
  338.     function &checkViewName($view_name)
  339.     {
  340.         $true true;
  341.         if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
  342.                        $view_name=== 0{
  343.             return Ethna::raiseError("invalid view name [$view_name]");
  344.         }
  345.         return $true;
  346.     }
  347.  
  348.     /**
  349.      *  DSNを返す
  350.      *
  351.      *  @access public
  352.      *  @param  string  $db_key DBキー
  353.      *  @return string  DSN
  354.      */
  355.     function getDSN($db_key "")
  356.     {
  357.         if (isset($this->dsn[$db_key]== false{
  358.             return null;
  359.         }
  360.         return $this->dsn[$db_key];
  361.     }
  362.  
  363.     /**
  364.      *  DSNの持続接続設定を返す
  365.      *
  366.      *  @access public
  367.      *  @param  string  $db_key DBキー
  368.      *  @return bool    true:persistent false:non-persistent(あるいは設定無し)
  369.      */
  370.     function getDSN_persistent($db_key "")
  371.     {
  372.         $key sprintf("dsn%s_persistent"$db_key == "" "" "_$db_key");
  373.  
  374.         $dsn_persistent $this->config->get($key);
  375.         if (is_null($dsn_persistent)) {
  376.             return false;
  377.         }
  378.         return $dsn_persistent;
  379.     }
  380.  
  381.     /**
  382.      *  DB設定を返す
  383.      *
  384.      *  @access public
  385.      *  @param  string  $db_key DBキー("", "r", "rw", "default", "blog_r"...)
  386.      *  @return string  $db_keyに対応するDB種別定義(設定が無い場合はnull)
  387.      */
  388.     function getDBType($db_key null)
  389.     {
  390.         if (is_null($db_key)) {
  391.             // 一覧を返す
  392.             return $this->db;
  393.         }
  394.  
  395.         if (isset($this->db[$db_key]== false{
  396.             return null;
  397.         }
  398.         return $this->db[$db_key];
  399.     }
  400.  
  401.     /**
  402.      *  アプリケーションベースURLを返す
  403.      *
  404.      *  @access public
  405.      *  @return string  アプリケーションベースURL
  406.      */
  407.     function getURL()
  408.     {
  409.         return $this->url;
  410.     }
  411.  
  412.     /**
  413.      *  アプリケーションベースディレクトリを返す
  414.      *
  415.      *  @access public
  416.      *  @return string  アプリケーションベースディレクトリ
  417.      */
  418.     function getBasedir()
  419.     {
  420.         return $this->base;
  421.     }
  422.  
  423.     /**
  424.      *  クライアントタイプ/言語からテンプレートディレクトリ名を決定する
  425.      *
  426.      *  @access public
  427.      *  @return string  テンプレートディレクトリ
  428.      */
  429.     function getTemplatedir()
  430.     {
  431.         $template $this->getDirectory('template');
  432.  
  433.         // 言語別ディレクトリ
  434.         if (file_exists($template '/' $this->language)) {
  435.             $template .= '/' $this->language;
  436.         }
  437.  
  438.         return $template;
  439.     }
  440.  
  441.     /**
  442.      *  アクションディレクトリ名を決定する
  443.      *
  444.      *  @access public
  445.      *  @return string  アクションディレクトリ
  446.      */
  447.     function getActiondir($gateway null)
  448.     {
  449.         $key 'action';
  450.         $gateway is_null($gateway$this->getGateway($gateway;
  451.         switch ($gateway{
  452.         case GATEWAY_WWW:
  453.             $key 'action';
  454.             break;
  455.         case GATEWAY_CLI:
  456.             $key 'action_cli';
  457.             break;
  458.         case GATEWAY_XMLRPC:
  459.             $key 'action_xmlrpc';
  460.             break;
  461.         }
  462.  
  463.         return (empty($this->directory[$key]($this->base (empty($this->base'' '/')) ($this->directory[$key"/"));
  464.     }
  465.  
  466.     /**
  467.      *  ビューディレクトリ名を決定する
  468.      *
  469.      *  @access public
  470.      *  @return string  ビューディレクトリ
  471.      */
  472.     function getViewdir()
  473.     {
  474.         return (empty($this->directory['view']($this->base (empty($this->base'' '/')) ($this->directory['view'"/"));
  475.     }
  476.  
  477.     /**
  478.      *  (action,view以外の)テストケースを置くディレクトリ名を決定する
  479.      *
  480.      *  @access public
  481.      *  @return string  テストケースを置くディレクトリ
  482.      */
  483.     function getTestdir()
  484.     {
  485.         return (empty($this->directory['test']($this->base (empty($this->base'' '/')) ($this->directory['test'"/"));
  486.     }
  487.  
  488.     /**
  489.      *  アプリケーションディレクトリ設定を返す
  490.      *
  491.      *  @access public
  492.      *  @param  string  $key    ディレクトリタイプ("tmp", "template"...)
  493.      *  @return string  $keyに対応したアプリケーションディレクトリ(設定が無い場合はnull)
  494.      */
  495.     function getDirectory($key)
  496.     {
  497.         // for B.C.
  498.         if ($key == 'app' && isset($this->directory[$key]== false{
  499.             return BASE '/app';
  500.         }
  501.  
  502.         if (isset($this->directory[$key]== false{
  503.             return null;
  504.         }
  505.         return $this->directory[$key];
  506.     }
  507.  
  508.     /**
  509.      *  アプリケーション拡張子設定を返す
  510.      *
  511.      *  @access public
  512.      *  @param  string  $key    拡張子タイプ("php", "tpl"...)
  513.      *  @return string  $keyに対応した拡張子(設定が無い場合はnull)
  514.      */
  515.     function getExt($key)
  516.     {
  517.         if (isset($this->ext[$key]== false{
  518.             return null;
  519.         }
  520.         return $this->ext[$key];
  521.     }
  522.  
  523.     /**
  524.      *  クラスファクトリオブジェクトのアクセサ(R)
  525.      *
  526.      *  @access public
  527.      *  @return object  Ethna_ClassFactory  クラスファクトリオブジェクト
  528.      */
  529.     function &getClassFactory()
  530.     {
  531.         return $this->class_factory;
  532.     }
  533.  
  534.     /**
  535.      *  アクションエラーオブジェクトのアクセサ
  536.      *
  537.      *  @access public
  538.      *  @return object  Ethna_ActionError   アクションエラーオブジェクト
  539.      */
  540.     function &getActionError()
  541.     {
  542.         return $this->class_factory->getObject('error');
  543.     }
  544.  
  545.     /**
  546.      *  アクションフォームオブジェクトのアクセサ
  547.      *
  548.      *  @access public
  549.      *  @return object  Ethna_ActionForm    アクションフォームオブジェクト
  550.      */
  551.     function &getActionForm()
  552.     {
  553.         // 明示的にクラスファクトリを利用していない
  554.         return $this->action_form;
  555.     }
  556.  
  557.     /**
  558.      *  ビューオブジェクトのアクセサ
  559.      *
  560.      *  @access public
  561.      *  @return object  Ethna_View          ビューオブジェクト
  562.      */
  563.     function &getView()
  564.     {
  565.         // 明示的にクラスファクトリを利用していない
  566.         return $this->view;
  567.     }
  568.  
  569.     /**
  570.      *  backendオブジェクトのアクセサ
  571.      *
  572.      *  @access public
  573.      *  @return object  Ethna_Backend   backendオブジェクト
  574.      */
  575.     function &getBackend()
  576.     {
  577.         return $this->class_factory->getObject('backend');
  578.     }
  579.  
  580.     /**
  581.      *  設定オブジェクトのアクセサ
  582.      *
  583.      *  @access public
  584.      *  @return object  Ethna_Config    設定オブジェクト
  585.      */
  586.     function &getConfig()
  587.     {
  588.         return $this->class_factory->getObject('config');
  589.     }
  590.  
  591.     /**
  592.      *  i18nオブジェクトのアクセサ(R)
  593.      *
  594.      *  @access public
  595.      *  @return object  Ethna_I18N  i18nオブジェクト
  596.      */
  597.     function &getI18N()
  598.     {
  599.         return $this->class_factory->getObject('i18n');
  600.     }
  601.  
  602.     /**
  603.      *  ログオブジェクトのアクセサ
  604.      *
  605.      *  @access public
  606.      *  @return object  Ethna_Logger        ログオブジェクト
  607.      */
  608.     function &getLogger()
  609.     {
  610.         return $this->class_factory->getObject('logger');
  611.     }
  612.  
  613.     /**
  614.      *  セッションオブジェクトのアクセサ
  615.      *
  616.      *  @access public
  617.      *  @return object  Ethna_Session       セッションオブジェクト
  618.      */
  619.     function &getSession()
  620.     {
  621.         return $this->class_factory->getObject('session');
  622.     }
  623.  
  624.     /**
  625.      *  SQLオブジェクトのアクセサ
  626.      *
  627.      *  @access public
  628.      *  @return object  Ethna_AppSQL    SQLオブジェクト
  629.      */
  630.     function &getSQL()
  631.     {
  632.         return $this->class_factory->getObject('sql');
  633.     }
  634.  
  635.     /**
  636.      *  プラグインオブジェクトのアクセサ
  637.      *
  638.      *  @access public
  639.      *  @return object  Ethna_Plugin    プラグインオブジェクト
  640.      */
  641.     function &getPlugin()
  642.     {
  643.         return $this->class_factory->getObject('plugin');
  644.     }
  645.  
  646.     /**
  647.      *  URLハンドラオブジェクトのアクセサ
  648.      *
  649.      *  @access public
  650.      *  @return object  Ethna_UrlHandler    URLハンドラオブジェクト
  651.      */
  652.     function &getUrlHandler()
  653.     {
  654.         return $this->class_factory->getObject('url_handler');
  655.     }
  656.  
  657.     /**
  658.      *  マネージャ一覧を返す
  659.      *
  660.      *  @access public
  661.      *  @return array   マネージャ一覧
  662.      *  @obsolete
  663.      */
  664.     function getManagerList()
  665.     {
  666.         return $this->manager;
  667.     }
  668.  
  669.     /**
  670.      *  実行中のアクション名を返す
  671.      *
  672.      *  @access public
  673.      *  @return string  実行中のアクション名
  674.      */
  675.     function getCurrentActionName()
  676.     {
  677.         return $this->action_name;
  678.     }
  679.  
  680.     /**
  681.      *  実行中のXMLRPCメソッド名を返す
  682.      *
  683.      *  @access public
  684.      *  @return string  実行中のXMLRPCメソッド名
  685.      */
  686.     function getXmlrpcMethodName()
  687.     {
  688.         return $this->xmlrpc_method_name;
  689.     }
  690.  
  691.     /**
  692.      *  使用言語を取得する
  693.      *
  694.      *  @access public
  695.      *  @return array   使用言語,システムエンコーディング名,クライアントエンコーディング名
  696.      */
  697.     function getLanguage()
  698.     {
  699.         return array($this->language$this->system_encoding$this->client_encoding);
  700.     }
  701.  
  702.     /**
  703.      *  ゲートウェイを取得する
  704.      *
  705.      *  @access public
  706.      */
  707.     function getGateway()
  708.     {
  709.         return $this->gateway;
  710.     }
  711.  
  712.     /**
  713.      *  ゲートウェイモードを設定する
  714.      *
  715.      *  @access public
  716.      */
  717.     function setGateway($gateway)
  718.     {
  719.         $this->gateway $gateway;
  720.     }
  721.  
  722.     /**
  723.      *  アプリケーションのエントリポイント
  724.      *
  725.      *  @access public
  726.      *  @param  string  $class_name     アプリケーションコントローラのクラス名
  727.      *  @param  mixed   $action_name    指定のアクション名(省略可)
  728.      *  @param  mixed   $fallback_action_name   アクションが決定できなかった場合に実行されるアクション名(省略可)
  729.      *  @static
  730.      */
  731.     function main($class_name$action_name ""$fallback_action_name "")
  732.     {
  733.         $c =new $class_name;
  734.         $c->trigger($action_name$fallback_action_name);
  735.     }
  736.  
  737.     /**
  738.      *  CLIアプリケーションのエントリポイント
  739.      *
  740.      *  @access public
  741.      *  @param  string  $class_name     アプリケーションコントローラのクラス名
  742.      *  @param  string  $action_name    実行するアクション名
  743.      *  @param  bool    $enable_filter  フィルタチェインを有効にするかどうか
  744.      *  @static
  745.      */
  746.     function main_CLI($class_name$action_name$enable_filter true)
  747.     {
  748.         $c =new $class_name(GATEWAY_CLI);
  749.         $c->action_cli[$action_namearray();
  750.         $c->trigger($action_name""$enable_filter);
  751.     }
  752.  
  753.     /**
  754.      *  XMLRPCアプリケーションのエントリポイント
  755.      *
  756.      *  @access public
  757.      *  @static
  758.      */
  759.     function main_XMLRPC($class_name)
  760.     {
  761.         if (extension_loaded('xmlrpc'== false{
  762.             die("xmlrpc extension is required to enable this gateway");
  763.         }
  764.  
  765.         $c =new $class_name(GATEWAY_XMLRPC);
  766.         $c->trigger(""""false);
  767.     }
  768.  
  769.     /**
  770.      *  SOAPアプリケーションのエントリポイント
  771.      *
  772.      *  @access public
  773.      *  @param  string  $class_name     アプリケーションコントローラのクラス名
  774.      *  @param  mixed   $action_name    指定のアクション名(省略可)
  775.      *  @param  mixed   $fallback_action_name   アクションが決定できなかった場合に実行されるアクション名(省略可)
  776.      *  @static
  777.      */
  778.     function main_SOAP($class_name$action_name ""$fallback_action_name "")
  779.     {
  780.         $c =new $class_name(GATEWAY_SOAP);
  781.         $c->trigger($action_name$fallback_action_name);
  782.     }
  783.  
  784.     /**
  785.      *  フレームワークの処理を開始する
  786.      *
  787.      *  @access public
  788.      *  @param  mixed   $default_action_name    指定のアクション名
  789.      *  @param  mixed   $fallback_action_name   アクション名が決定できなかった場合に実行されるアクション名
  790.      *  @param  bool    $enable_filter  フィルタチェインを有効にするかどうか
  791.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  792.      */
  793.     function trigger($default_action_name ""$fallback_action_name ""$enable_filter true)
  794.     {
  795.         // フィルターの生成
  796.         if ($enable_filter{
  797.             $this->_createFilterChain();
  798.         }
  799.  
  800.         // 実行前フィルタ
  801.         for ($i 0$i count($this->filter_chain)$i++{
  802.             $r $this->filter_chain[$i]->preFilter();
  803.             if (Ethna::isError($r)) {
  804.                 return $r;
  805.             }
  806.         }
  807.  
  808.         // trigger
  809.         switch ($this->getGateway()) {
  810.         case GATEWAY_WWW:
  811.             $this->_trigger_WWW($default_action_name$fallback_action_name);
  812.             break;
  813.         case GATEWAY_CLI:
  814.             $this->_trigger_CLI($default_action_name);
  815.             break;
  816.         case GATEWAY_XMLRPC:
  817.             $this->_trigger_XMLRPC();
  818.             break;
  819.         case GATEWAY_SOAP:
  820.             $this->_trigger_SOAP();
  821.             break;
  822.         }
  823.  
  824.         // 実行後フィルタ
  825.         for ($i count($this->filter_chain1$i >= 0$i--{
  826.             $r $this->filter_chain[$i]->postFilter();
  827.             if (Ethna::isError($r)) {
  828.                 return $r;
  829.             }
  830.         }
  831.     }
  832.  
  833.     /**
  834.      *  フレームワークの処理を実行する(WWW)
  835.      *
  836.      *  引数$default_action_nameに配列が指定された場合、その配列で指定された
  837.      *  アクション以外は受け付けない(指定されていないアクションが指定された
  838.      *  場合、配列の先頭で指定されたアクションが実行される)
  839.      *
  840.      *  @access private
  841.      *  @param  mixed   $default_action_name    指定のアクション名
  842.      *  @param  mixed   $fallback_action_name   アクション名が決定できなかった場合に実行されるアクション名
  843.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  844.      */
  845.     function _trigger_WWW($default_action_name ""$fallback_action_name "")
  846.     {
  847.         // アクション名の取得
  848.         $action_name $this->_getActionName($default_action_name$fallback_action_name);
  849.  
  850.         // マネージャ実行チェック
  851.         $this->_ethnaManagerEnabledCheck($action_name);
  852.  
  853.         // アクション定義の取得
  854.         $action_obj =$this->_getAction($action_name);
  855.         if (is_null($action_obj)) {
  856.             if ($fallback_action_name != ""{
  857.                 $this->logger->log(LOG_DEBUG'undefined action [%s] -> try fallback action [%s]'$action_name$fallback_action_name);
  858.                 $action_obj =$this->_getAction($fallback_action_name);
  859.             }
  860.             if (is_null($action_obj)) {
  861.                 return Ethna::raiseError("undefined action [%s]"E_APP_UNDEFINED_ACTION$action_name);
  862.             else {
  863.                 $action_name $fallback_action_name;
  864.             }
  865.         }
  866.  
  867.         // アクション実行前フィルタ
  868.         for ($i 0$i count($this->filter_chain)$i++{
  869.             $r $this->filter_chain[$i]->preActionFilter($action_name);
  870.             if ($r != null{
  871.                 $this->logger->log(LOG_DEBUG'action [%s] -> [%s] by %s'$action_name$rget_class($this->filter_chain[$i]));
  872.                 $action_name $r;
  873.             }
  874.         }
  875.         $this->action_name $action_name;
  876.  
  877.         // 言語設定
  878.         $this->_setLanguage($this->language$this->system_encoding$this->client_encoding);
  879.  
  880.         // オブジェクト生成
  881.         $backend =$this->getBackend();
  882.  
  883.         $form_name $this->getActionFormName($action_name);
  884.         $this->action_form =new $form_name($this);
  885.         $this->action_form->setFormVars();
  886.  
  887.         // バックエンド処理実行
  888.         $backend->setActionForm($this->action_form);
  889.  
  890.         $session =$this->getSession();
  891.         $session->restore();
  892.         $forward_name $backend->perform($action_name);
  893.  
  894.         // アクション実行後フィルタ
  895.         for ($i count($this->filter_chain1$i >= 0$i--{
  896.             $r $this->filter_chain[$i]->postActionFilter($action_name$forward_name);
  897.             if ($r != null{
  898.                 $this->logger->log(LOG_DEBUG'forward [%s] -> [%s] by %s'$forward_name$rget_class($this->filter_chain[$i]));
  899.                 $forward_name $r;
  900.             }
  901.         }
  902.  
  903.         // コントローラで遷移先を決定する(オプション)
  904.         $forward_name $this->_sortForward($action_name$forward_name);
  905.  
  906.         if ($forward_name != null{
  907.             $view_class_name $this->getViewClassName($forward_name);
  908.             $this->view =new $view_class_name($backend$forward_name$this->_getForwardPath($forward_name));
  909.             $this->view->preforward();
  910.             $this->view->forward();
  911.         }
  912.  
  913.         return 0;
  914.     }
  915.  
  916.     /**
  917.      *  フレームワークの処理を実行する(CLI)
  918.      *
  919.      *  @access private
  920.      *  @param  mixed   $default_action_name    指定のアクション名
  921.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  922.      */
  923.     function _trigger_CLI($default_action_name "")
  924.     {
  925.         return $this->_trigger_WWW($default_action_name);
  926.     }
  927.  
  928.     /**
  929.      *  フレームワークの処理を実行する(XMLRPC)
  930.      *
  931.      *  @access private
  932.      *  @param  mixed   $action_name    指定のアクション名
  933.      *  @return mixed   0:正常終了 Ethna_Error:エラー
  934.      */
  935.     function _trigger_XMLRPC($action_name "")
  936.     {
  937.         // prepare xmlrpc server
  938.         $xmlrpc_gateway_method_name "_Ethna_XmlrpcGateway";
  939.         $xmlrpc_server xmlrpc_server_create();
  940.  
  941.         $method null;
  942.         $param xmlrpc_decode_request(file_get_contents('php://input')$method);
  943.         $this->xmlrpc_method_name $method;
  944.  
  945.         $request xmlrpc_encode_request(
  946.             $xmlrpc_gateway_method_name,
  947.             $param,
  948.             array(
  949.                 'output_type'   => 'xml',
  950.                 'verbosity'     => 'pretty',
  951.                 'escaping'      => array('markup'),
  952.                 'version'       => 'xmlrpc',
  953.                 'encoding'      => 'utf-8'
  954.             )
  955.         )
  956.  
  957.         xmlrpc_server_register_method(
  958.             $xmlrpc_server,
  959.             $xmlrpc_gateway_method_name,
  960.             $xmlrpc_gateway_method_name
  961.         );
  962.  
  963.         // send request
  964.         $r xmlrpc_server_call_method(
  965.             $xmlrpc_server,
  966.             $request,
  967.             null,
  968.             array(
  969.                 'output_type'   => 'xml',
  970.                 'verbosity'     => 'pretty',
  971.                 'escaping'      => array('markup'),
  972.                 'version'       => 'xmlrpc',
  973.                 'encoding'      => 'utf-8'
  974.             )
  975.         );
  976.  
  977.         header('Content-Length: ' strlen($r));
  978.         header('Content-Type: text/xml; charset=UTF-8');
  979.         print $r;
  980.     }
  981.  
  982.     /**
  983.      *  _trigger_XMLRPCのコールバックメソッド
  984.      *
  985.      *  @access public
  986.      */
  987.     function trigger_XMLRPC($method$param)
  988.     {
  989.         // アクション定義の取得
  990.         $action_obj =$this->_getAction($method);
  991.         if (is_null($action_obj)) {
  992.             return Ethna::raiseError("undefined xmlrpc method [%s]"E_APP_UNDEFINED_ACTION$method);
  993.         }
  994.  
  995.         // オブジェクト生成
  996.         $backend =$this->getBackend();
  997.  
  998.         $form_name $this->getActionFormName($method);
  999.         $this->action_form =new $form_name($this);
  1000.         $def $this->action_form->getDef();
  1001.         $n 0;
  1002.         foreach ($def as $key => $value{
  1003.             if (isset($param[$n]== false{
  1004.                 $this->action_form->set($keynull);
  1005.             else {
  1006.                 $this->action_form->set($key$param[$n]);
  1007.             }
  1008.             $n++;
  1009.         }
  1010.  
  1011.         // バックエンド処理実行
  1012.         $backend->setActionForm($this->action_form);
  1013.  
  1014.         $session =$this->getSession();
  1015.         $session->restore();
  1016.         $r $backend->perform($method);
  1017.  
  1018.         return $r;
  1019.     }
  1020.  
  1021.     /**
  1022.      *  SOAPフレームワークの処理を実行する
  1023.      *
  1024.      *  @access private
  1025.      */
  1026.     function _trigger_SOAP()
  1027.     {
  1028.         // SOAPエントリクラス
  1029.         $gg =new Ethna_SOAP_GatewayGenerator();
  1030.         $script $gg->generate();
  1031.         eval($script);
  1032.  
  1033.         // SOAPリクエスト処理
  1034.         $server =new SoapServer(nullarray('uri' => $this->config->get('url')));
  1035.         $server->setClass($gg->getClassName());
  1036.         $server->handle();
  1037.     }
  1038.  
  1039.     /**
  1040.      *  エラーハンドラ
  1041.      *
  1042.      *  エラー発生時の追加処理を行いたい場合はこのメソッドをオーバーライドする
  1043.      *  (アラートメール送信等−デフォルトではログ出力時にアラートメール
  1044.      *  が送信されるが、エラー発生時に別にアラートメールをここで送信
  1045.      *  させることも可能)
  1046.      *
  1047.      *  @access public
  1048.      *  @param  object  Ethna_Error     エラーオブジェクト
  1049.      */
  1050.     function handleError(&$error)
  1051.     {
  1052.         // ログ出力
  1053.         list ($log_level$dummy$this->logger->errorLevelToLogLevel($error->getLevel());
  1054.         $message $error->getMessage();
  1055.         $this->logger->log($log_levelsprintf("%s [ERROR CODE(%d)]"$message$error->getCode()));
  1056.     }
  1057.  
  1058.     /**
  1059.      *  エラーメッセージを取得する
  1060.      *
  1061.      *  @access public
  1062.      *  @param  int     $code       エラーコード
  1063.      *  @return string  エラーメッセージ
  1064.      */
  1065.     function getErrorMessage($code)
  1066.     {
  1067.         $message_list =$GLOBALS['_Ethna_error_message_list'];
  1068.         for ($i count($message_list)-1$i >= 0$i--{
  1069.             if (array_key_exists($code$message_list[$i])) {
  1070.                 return $message_list[$i][$code];
  1071.             }
  1072.         }
  1073.         return null;
  1074.     }
  1075.  
  1076.     /**
  1077.      *  実行するアクション名を返す
  1078.      *
  1079.      *  @access private
  1080.      *  @param  mixed   $default_action_name    指定のアクション名
  1081.      *  @return string  実行するアクション名
  1082.      */
  1083.     function _getActionName($default_action_name$fallback_action_name)
  1084.     {
  1085.         // フォームから要求されたアクション名を取得する
  1086.         $form_action_name $this->_getActionName_Form();
  1087.         $form_action_name preg_replace('/[^a-z0-9\-_]+/i'''$form_action_name);
  1088.         $this->logger->log(LOG_DEBUG'form_action_name[%s]'$form_action_name);
  1089.  
  1090.         // Ethnaマネージャへのフォームからのリクエストは拒否
  1091.         if ($form_action_name == "__ethna_info__" ||
  1092.             $form_action_name == "__ethna_unittest__"{
  1093.             $form_action_name "";
  1094.         }
  1095.  
  1096.         // フォームからの指定が無い場合はエントリポイントに指定されたデフォルト値を利用する
  1097.         if ($form_action_name == "" && count($default_action_name0{
  1098.             $tmp is_array($default_action_name$default_action_name[0$default_action_name;
  1099.             if ($tmp{strlen($tmp)-1== '*'{
  1100.                 $tmp substr($tmp0-1);
  1101.             }
  1102.             $this->logger->log(LOG_DEBUG'-> default_action_name[%s]'$tmp);
  1103.             $action_name $tmp;
  1104.         else {
  1105.             $action_name $form_action_name;
  1106.         }
  1107.  
  1108.         // エントリポイントに配列が指定されている場合は指定以外のアクション名は拒否する
  1109.         if (is_array($default_action_name)) {
  1110.             if ($this->_isAcceptableActionName($action_name$default_action_name== false{
  1111.                 // 指定以外のアクション名で合った場合は$fallback_action_name(or デフォルト)
  1112.                 $tmp $fallback_action_name != "" $fallback_action_name $default_action_name[0];
  1113.                 if ($tmp{strlen($tmp)-1== '*'{
  1114.                     $tmp substr($tmp0-1);
  1115.                 }
  1116.                 $this->logger->log(LOG_DEBUG'-> fallback_action_name[%s]'$tmp);
  1117.                 $action_name $tmp;
  1118.             }
  1119.         }
  1120.  
  1121.         $this->logger->log(LOG_DEBUG'<<< action_name[%s] >>>'$action_name);
  1122.  
  1123.         return $action_name;
  1124.     }
  1125.  
  1126.     /**
  1127.      *  フォームにより要求されたアクション名を返す
  1128.      *
  1129.      *  アプリケーションの性質に応じてこのメソッドをオーバーライドして下さい。
  1130.      *  デフォルトでは"action_"で始まるフォーム値の"action_"の部分を除いたもの
  1131.      *  ("action_sample"なら"sample")がアクション名として扱われます
  1132.      *
  1133.      *  @access protected
  1134.      *  @return string  フォームにより要求されたアクション名
  1135.      */
  1136.     function _getActionName_Form()
  1137.     {
  1138.         if (isset($_SERVER['REQUEST_METHOD']== false{
  1139.             return null;
  1140.         }
  1141.  
  1142.         $url_handler =$this->getUrlHandler();
  1143.         if ($_SERVER['REQUEST_METHOD'== "GET"{
  1144.             $tmp_vars $_GET;
  1145.         else if ($_SERVER['REQUEST_METHOD'== "POST"{
  1146.             $tmp_vars $_POST;
  1147.         }
  1148.  
  1149.         if (empty($_SERVER['URL_HANDLER']== false{
  1150.             $tmp_vars['__url_handler__'$_SERVER['URL_HANDLER'];
  1151.             $tmp_vars['__url_info__'= isset($_SERVER['PATH_INFO']$_SERVER['PATH_INFO'null;
  1152.             $tmp_vars $url_handler->requestToAction($tmp_vars);
  1153.  
  1154.             if ($_SERVER['REQUEST_METHOD'== "GET"{
  1155.                 $_GET array_merge($_GET$tmp_vars);
  1156.             else if ($_SERVER['REQUEST_METHOD'== "POST"{
  1157.                 $_POST array_merge($_POST$tmp_vars);
  1158.             }
  1159.             $_REQUEST array_merge($_REQUEST$tmp_vars);
  1160.         }
  1161.  
  1162.         if (strcasecmp($_SERVER['REQUEST_METHOD']'post'== 0{
  1163.             $http_vars =$_POST;
  1164.         else {
  1165.             $http_vars =$_GET;
  1166.         }
  1167.  
  1168.         // フォーム値からリクエストされたアクション名を取得する
  1169.         $action_name $sub_action_name null;
  1170.         foreach ($http_vars as $name => $value{
  1171.             if ($value == "" || strncmp($name'action_'7!= 0{
  1172.                 continue;
  1173.             }
  1174.  
  1175.             $tmp substr($name7);
  1176.  
  1177.             // type="image"対応
  1178.             if (preg_match('/_x$/'$name|| preg_match('/_y$/'$name)) {
  1179.                 $tmp substr($tmp0strlen($tmp)-2);
  1180.             }
  1181.  
  1182.             // value="dummy"となっているものは優先度を下げる
  1183.             if ($value == "dummy"{
  1184.                 $sub_action_name $tmp;
  1185.             else {
  1186.                 $action_name $tmp;
  1187.             }
  1188.         }
  1189.         if ($action_name == null{
  1190.             $action_name $sub_action_name;
  1191.         }
  1192.  
  1193.         return $action_name;
  1194.     }
  1195.  
  1196.     /**
  1197.      *  アクション名を指定するクエリ/HTMLを生成する
  1198.      *
  1199.      *  @access public
  1200.      *  @param  string  $action action to request
  1201.      *  @param  string  $type   hidden, url...
  1202.      *  @todo   consider gateway
  1203.      */
  1204.     function getActionRequest($action$type "hidden")
  1205.     {
  1206.         $s null
  1207.         if ($type == "hidden"{
  1208.             $s sprintf('<input type="hidden" name="action_%s" value="true">'htmlspecialchars($actionENT_QUOTES));
  1209.         else if ($type == "url"{
  1210.             $s sprintf('action_%s=true'urlencode($action));
  1211.         }
  1212.         return $s;
  1213.     }
  1214.  
  1215.     /**
  1216.      *  フォームにより要求されたアクション名に対応する定義を返す
  1217.      *
  1218.      *  @access private
  1219.      *  @param  string  $action_name    アクション名
  1220.      *  @return array   アクション定義
  1221.      */
  1222.     function &_getAction($action_name$gateway null)
  1223.     {
  1224.         $action array();
  1225.         $gateway is_null($gateway$this->getGateway($gateway;
  1226.         switch ($gateway{
  1227.         case GATEWAY_WWW:
  1228.             $action =$this->action;
  1229.             break;
  1230.         case GATEWAY_CLI:
  1231.             $action =$this->action_cli;
  1232.             break;
  1233.         case GATEWAY_XMLRPC:
  1234.             $action =$this->action_xmlrpc;
  1235.             break;
  1236.         }
  1237.  
  1238.         $action_obj array();
  1239.         if (isset($action[$action_name])) {
  1240.             $action_obj $action[$action_name];
  1241.             if (isset($action_obj['inspect']&& $action_obj['inspect']{
  1242.                 return $action_obj;
  1243.             }
  1244.         else {
  1245.             $this->logger->log(LOG_DEBUG"action [%s] is not defined -> try default"$action_name);
  1246.         }
  1247.  
  1248.         // アクションスクリプトのインクルード
  1249.         $this->_includeActionScript($action_obj$action_name);
  1250.  
  1251.         // 省略値の補正
  1252.         if (isset($action_obj['class_name']== false{
  1253.             $action_obj['class_name'$this->getDefaultActionClass($action_name);
  1254.         }
  1255.  
  1256.         if (isset($action_obj['form_name']== false{
  1257.             $action_obj['form_name'$this->getDefaultFormClass($action_name);
  1258.         else if (class_exists($action_obj['form_name']== false{
  1259.             // 明示指定されたフォームクラスが定義されていない場合は警告
  1260.             $this->logger->log(LOG_WARNING'stated form class is not defined [%s]'$action_obj['form_name']);
  1261.         }
  1262.  
  1263.         // 必要条件の確認
  1264.         if (class_exists($action_obj['class_name']== false{
  1265.             $this->logger->log(LOG_NOTICE'action class is not defined [%s]'$action_obj['class_name']);
  1266.             $_ret_object null;
  1267.             return $_ret_object;
  1268.         }
  1269.         if (class_exists($action_obj['form_name']== false{
  1270.             // フォームクラスは未定義でも良い
  1271.             $class_name $this->class_factory->getObjectName('form');
  1272.             $this->logger->log(LOG_DEBUG'form class is not defined [%s] -> falling back to default [%s]'$action_obj['form_name']$class_name);
  1273.             $action_obj['form_name'$class_name;
  1274.         }
  1275.  
  1276.         $action_obj['inspect'true;
  1277.         $action[$action_name$action_obj;
  1278.         return $action[$action_name];
  1279.     }
  1280.  
  1281.     /**
  1282.      *  アクション名とアクションクラスからの戻り値に基づいて遷移先を決定する
  1283.      *
  1284.      *  @access protected
  1285.      *  @param  string  $action_name    アクション名
  1286.      *  @param  string  $retval         アクションクラスからの戻り値
  1287.      *  @return string  遷移先
  1288.      */
  1289.     function _sortForward($action_name$retval)
  1290.     {
  1291.         return $retval;
  1292.     }
  1293.  
  1294.     /**
  1295.      *  フィルタチェインを生成する
  1296.      *
  1297.      *  @access private
  1298.      */
  1299.     function _createFilterChain()
  1300.     {
  1301.         $this->filter_chain array();
  1302.         foreach ($this->filter as $filter{
  1303.             //バージョン0.2.0以前のフィルタ群から探す
  1304.             $file sprintf("%s/%s.%s"$this->getDirectory('filter')$filter,$this->getExt('php'));
  1305.             if (file_exists($file)) {
  1306.                 include_once $file;
  1307.                 if (class_exists($filter)) {
  1308.                     $this->filter_chain[=new $filter($this);
  1309.                 }
  1310.             else {  //プラグインから探す.
  1311.                 $filter_plugin =$this->plugin->getPlugin('Filter'$filter);
  1312.                 if (Ethna::isError($filter_plugin)) {
  1313.                     continue;
  1314.                 }
  1315.  
  1316.                 $this->filter_chain[=$filter_plugin;
  1317.             }
  1318.         }
  1319.     }
  1320.  
  1321.     /**
  1322.      *  アクション名が実行許可されているものかどうかを返す
  1323.      *
  1324.      *  @access private
  1325.      *  @param  string  $action_name            リクエストされたアクション名
  1326.      *  @param  array   $default_action_name    許可されているアクション名
  1327.      *  @return bool    true:許可 false:不許可
  1328.      */
  1329.     function _isAcceptableActionName($action_name$default_action_name)
  1330.     {
  1331.         foreach (to_array($default_action_nameas $name{
  1332.             if ($action_name == $name{
  1333.                 return true;
  1334.             else if ($name{strlen($name)-1== '*'{
  1335.                 if (strncmp($action_namesubstr($name0-1)strlen($name)-1== 0{
  1336.                     return true;
  1337.                 }
  1338.             }
  1339.         }
  1340.         return false;
  1341.     }
  1342.  
  1343.     /**
  1344.      *  指定されたアクションのフォームクラス名を返す(オブジェクトの生成は行わない)
  1345.      *
  1346.      *  @access public
  1347.      *  @param  string  $action_name    アクション名
  1348.      *  @return string  アクションのフォームクラス名
  1349.      */
  1350.     function getActionFormName($action_name)
  1351.     {
  1352.         $action_obj =$this->_getAction($action_name);
  1353.         if (is_null($action_obj)) {
  1354.             return null;
  1355.         }
  1356.  
  1357.         return $action_obj['form_name'];
  1358.     }
  1359.  
  1360.     /**
  1361.      *  アクションに対応するフォームクラス名が省略された場合のデフォルトクラス名を返す
  1362.      *
  1363.      *  デフォルトでは[プロジェクトID]_Form_[アクション名]となるので好み応じてオーバライドする
  1364.      *
  1365.      *  @access public
  1366.      *  @param  string  $action_name    アクション名
  1367.      *  @return string  アクションフォーム名
  1368.      */
  1369.     function getDefaultFormClass($action_name$gateway null)
  1370.     {
  1371.         $gateway_prefix $this->_getGatewayPrefix($gateway);
  1372.  
  1373.         $postfix preg_replace('/_(.)/e'"strtoupper('\$1')"ucfirst($action_name));
  1374.         $r sprintf("%s_%sForm_%s"$this->getAppId()$gateway_prefix $gateway_prefix "_" ""$postfix);
  1375.         $this->logger->log(LOG_DEBUG"default action class [%s]"$r);
  1376.  
  1377.         return $r;
  1378.     }
  1379.  
  1380.     /**
  1381.      *  getDefaultFormClass()で取得したクラス名からアクション名を取得する
  1382.      *
  1383.      *  getDefaultFormClass()をオーバーライドした場合、こちらも合わせてオーバーライド
  1384.      *  することを推奨(必須ではない)
  1385.      *
  1386.      *  @access public
  1387.      *  @param  string  $class_name     フォームクラス名
  1388.      *  @return string  アクション名
  1389.      */
  1390.     function actionFormToName($class_name)
  1391.     {
  1392.         $prefix sprintf("%s_Form_"$this->getAppId());
  1393.         if (preg_match("/$prefix(.*)/"$class_name$match== 0{
  1394.             // 不明なクラス名
  1395.             return null;
  1396.         }
  1397.         $target $match[1];
  1398.  
  1399.         $action_name substr(preg_replace('/([A-Z])/e'"'_' . strtolower('\$1')"$target)1);
  1400.  
  1401.         return $action_name;
  1402.     }
  1403.  
  1404.     /**
  1405.      *  アクションに対応するフォームパス名が省略された場合のデフォルトパス名を返す
  1406.      *
  1407.      *  デフォルトでは_getDefaultActionPath()と同じ結果を返す(1ファイルに
  1408.      *  アクションクラスとフォームクラスが記述される)ので、好みに応じて
  1409.      *  オーバーライドする
  1410.      *
  1411.      *  @access public
  1412.      *  @param  string  $action_name    アクション名
  1413.      *  @return string  form classが定義されるスクリプトのパス名
  1414.      */
  1415.     function getDefaultFormPath($action_name)
  1416.     {
  1417.         return $this->getDefaultActionPath($action_name);
  1418.     }
  1419.  
  1420.     /**
  1421.      *  指定されたアクションのクラス名を返す(オブジェクトの生成は行わない)
  1422.      *
  1423.      *  @access public
  1424.      *  @param  string  $action_name    アクションの名称
  1425.      *  @return string  アクションのクラス名
  1426.      */
  1427.     function getActionClassName($action_name)
  1428.     {
  1429.         $action_obj =$this->_getAction($action_name);
  1430.         if ($action_obj == null{
  1431.             return null;
  1432.         }
  1433.  
  1434.         return $action_obj['class_name'];
  1435.     }
  1436.  
  1437.     /**
  1438.      *  アクションに対応するアクションクラス名が省略された場合のデフォルトクラス名を返す
  1439.      *
  1440.      *  デフォルトでは[プロジェクトID]_Action_[アクション名]となるので好み応じてオーバライドする
  1441.      *
  1442.      *  @access public
  1443.      *  @param  string  $action_name    アクション名
  1444.      *  @return string  アクションクラス名
  1445.      */
  1446.     function getDefaultActionClass($action_name$gateway null)
  1447.     {
  1448.         $gateway_prefix $this->_getGatewayPrefix($gateway);
  1449.  
  1450.         $postfix preg_replace('/_(.)/e'"strtoupper('\$1')"ucfirst($action_name));
  1451.         $r sprintf("%s_%sAction_%s"$this->getAppId()$gateway_prefix $gateway_prefix "_" ""$postfix);
  1452.         $this->logger->log(LOG_DEBUG"default action class [%s]"$r);
  1453.  
  1454.         return $r;
  1455.     }
  1456.  
  1457.     /**
  1458.      *  getDefaultActionClass()で取得したクラス名からアクション名を取得する
  1459.      *
  1460.      *  getDefaultActionClass()をオーバーライドした場合、こちらも合わせてオーバーライド
  1461.      *  することを推奨(必須ではない)
  1462.      *
  1463.      *  @access public
  1464.      *  @param  string  $class_name     アクションクラス名
  1465.      *  @return string  アクション名
  1466.      */
  1467.     function actionClassToName($class_name)
  1468.     {
  1469.         $prefix sprintf("%s_Action_"$this->getAppId());
  1470.         if (preg_match("/$prefix(.*)/"$class_name$match== 0{
  1471.             // 不明なクラス名
  1472.             return null;
  1473.         }
  1474.         $target $match[1];
  1475.  
  1476.         $action_name substr(preg_replace('/([A-Z])/e'"'_' . strtolower('\$1')"$target)1);
  1477.  
  1478.         return $action_name;
  1479.     }
  1480.  
  1481.     /**
  1482.      *  アクションに対応するアクションパス名が省略された場合のデフォルトパス名を返す
  1483.      *
  1484.      *  デフォルトでは"foo_bar" -> "/Foo/Bar.php"となるので好み応じてオーバーライドする
  1485.      *
  1486.      *  @access public
  1487.      *  @param  string  $action_name    アクション名
  1488.      *  @return string  アクションクラスが定義されるスクリプトのパス名
  1489.      */
  1490.     function getDefaultActionPath($action_name)
  1491.     {
  1492.         $r preg_replace('/_(.)/e'"'/' . strtoupper('\$1')"ucfirst($action_name)) '.' $this->getExt('php');
  1493.         $this->logger->log(LOG_DEBUG"default action path [%s]"$r);
  1494.  
  1495.         return $r;
  1496.     }
  1497.  
  1498.     /**
  1499.      *  指定された遷移名に対応するビュークラス名を返す(オブジェクトの生成は行わない)
  1500.      *
  1501.      *  @access public
  1502.      *  @param  string  $forward_name   遷移先の名称
  1503.      *  @return string  view classのクラス名
  1504.      */
  1505.     function getViewClassName($forward_name)
  1506.     {
  1507.         if ($forward_name == null{
  1508.             return null;
  1509.         }
  1510.  
  1511.         if (isset($this->forward[$forward_name])) {
  1512.             $forward_obj $this->forward[$forward_name];
  1513.         else {
  1514.             $forward_obj array();
  1515.         }
  1516.  
  1517.         if (isset($forward_obj['view_name'])) {
  1518.             $class_name $forward_obj['view_name'];
  1519.             if (class_exists($class_name)) {
  1520.                 return $class_name;
  1521.             }
  1522.         else {
  1523.             $class_name null;
  1524.         }
  1525.  
  1526.         // viewのインクルード
  1527.         $this->_includeViewScript($forward_obj$forward_name);
  1528.  
  1529.         if (is_null($class_name== false && class_exists($class_name)) {
  1530.             return $class_name;
  1531.         else if (is_null($class_name== false{
  1532.             $this->logger->log(LOG_WARNING'stated view class is not defined [%s] -> try default'$class_name);
  1533.         }
  1534.  
  1535.         $class_name $this->getDefaultViewClass($forward_name);
  1536.         if (class_exists($class_name)) {
  1537.             return $class_name;
  1538.         else {
  1539.             $class_name $this->class_factory->getObjectName('view');
  1540.             $this->logger->log(LOG_DEBUG'view class is not defined for [%s] -> use default [%s]'$forward_name$class_name);
  1541.             return $class_name;
  1542.         }
  1543.     }
  1544.  
  1545.     /**
  1546.      *  遷移名に対応するビュークラス名が省略された場合のデフォルトクラス名を返す
  1547.      *
  1548.      *  デフォルトでは[プロジェクトID]_View_[遷移名]となるので好み応じてオーバライドする
  1549.      *
  1550.      *  @access public
  1551.      *  @param  string  $forward_name   forward名
  1552.      *  @return string  view classクラス名
  1553.      */
  1554.     function getDefaultViewClass($forward_name$gateway null)
  1555.     {
  1556.         $gateway_prefix $this->_getGatewayPrefix($gateway);
  1557.  
  1558.         $postfix preg_replace('/_(.)/e'"strtoupper('\$1')"ucfirst($forward_name));
  1559.         $r sprintf("%s_%sView_%s"$this->getAppId()$gateway_prefix $gateway_prefix "_" ""$postfix);
  1560.         $this->logger->log(LOG_DEBUG"default view class [%s]"$r);
  1561.  
  1562.         return $r;
  1563.     }
  1564.  
  1565.     /**
  1566.      *  遷移名に対応するビューパス名が省略された場合のデフォルトパス名を返す
  1567.      *
  1568.      *  デフォルトでは"foo_bar" -> "/Foo/Bar.php"となるので好み応じてオーバーライドする
  1569.      *
  1570.      *  @access public
  1571.      *  @param  string  $forward_name   forward名
  1572.      *  @return string  view classが定義されるスクリプトのパス名
  1573.      */
  1574.     function getDefaultViewPath($forward_name)
  1575.     {
  1576.         $r preg_replace('/_(.)/e'"'/' . strtoupper('\$1')"ucfirst($forward_name)) '.' $this->getExt('php');
  1577.         $this->logger->log(LOG_DEBUG"default view path [%s]"$r);
  1578.  
  1579.         return $r;
  1580.     }
  1581.  
  1582.     /**
  1583.      *  遷移名に対応するテンプレートパス名が省略された場合のデフォルトパス名を返す
  1584.      *
  1585.      *  デフォルトでは"foo_bar"というforward名が"foo/bar" + テンプレート拡張子となる
  1586.      *  ので好み応じてオーバライドする
  1587.      *
  1588.      *  @access public
  1589.      *  @param  string  $forward_name   forward名
  1590.      *  @return string  forwardパス名
  1591.      */
  1592.     function getDefaultForwardPath($forward_name)
  1593.     {
  1594.         return str_replace('_''/'$forward_name'.' $this->ext['tpl'];
  1595.     }
  1596.     
  1597.     /**
  1598.      *  テンプレートパス名から遷移名を取得する
  1599.      *
  1600.      *  getDefaultForwardPath()をオーバーライドした場合、こちらも合わせてオーバーライド
  1601.      *  することを推奨(必須ではない)
  1602.      *
  1603.      *  @access public
  1604.      *  @param  string  $forward_path   テンプレートパス名
  1605.      *  @return string  遷移名
  1606.      */
  1607.     function forwardPathToName($forward_path)
  1608.     {
  1609.         $forward_path preg_replace('/^\/+/'''$forward_path);
  1610.         $forward_path preg_replace(sprintf('/\.%s$/'$this->getExt('tpl'))''$forward_path);
  1611.  
  1612.         return str_replace('/''_'$forward_path);
  1613.     }
  1614.  
  1615.     /**
  1616.      *  遷移名からテンプレートファイルのパス名を取得する
  1617.      *
  1618.      *  @access private
  1619.      *  @param  string  $forward_name   forward名
  1620.      *  @return string  テンプレートファイルのパス名
  1621.      */
  1622.     function _getForwardPath($forward_name)
  1623.     {
  1624.         $forward_obj null;
  1625.  
  1626.         if (isset($this->forward[$forward_name]== false{
  1627.             // try default
  1628.             $this->forward[$forward_namearray();
  1629.         }
  1630.         $forward_obj =$this->forward[$forward_name];
  1631.         if (isset($forward_obj['forward_path']== false{
  1632.             // 省略値補正
  1633.             $forward_obj['forward_path'$this->getDefaultForwardPath($forward_name);
  1634.         }
  1635.  
  1636.         return $forward_obj['forward_path'];
  1637.     }
  1638.  
  1639.     /**
  1640.      *  レンダラを取得する(getTemplateEngine()はそのうち廃止されgetRenderer()に統合される予定)
  1641.      *
  1642.      *  @access public
  1643.      *  @return object  Ethna_Renderer  レンダラオブジェクト
  1644.      */
  1645.     function &getRenderer()
  1646.     {
  1647.         $_ret_object =$this->getTemplateEngine();
  1648.         return $_ret_object;
  1649.     }
  1650.  
  1651.     /**
  1652.      *  テンプレートエンジン取得する
  1653.      *
  1654.      *  @access public
  1655.      *  @return object  Ethna_Renderer  レンダラオブジェクト
  1656.      *  @obsolete
  1657.      */
  1658.     function &getTemplateEngine()
  1659.     {
  1660.         if (is_object($this->renderer)) {
  1661.             return $this->renderer;
  1662.         }
  1663.         
  1664.         $this->renderer =$this->class_factory->getObject('renderer');
  1665.        
  1666.         // {{{ for B.C.
  1667.         if (strtolower(get_class($this->renderer)) == "ethna_renderer_smarty"{
  1668.             // user defined modifiers
  1669.             foreach ($this->smarty_modifier_plugin as $modifier{
  1670.                 $name str_replace('smarty_modifier_'''$modifier);
  1671.                 $this->renderer->setPlugin($name,'modifier'$modifier);
  1672.             }
  1673.  
  1674.             // user defined functions
  1675.             foreach ($this->smarty_function_plugin as $function{
  1676.                 if (!is_array($function)) {
  1677.                     $name str_replace('smarty_function_'''$function);
  1678.                     $this->renderer->setPlugin($name'function'$function);
  1679.                 else {
  1680.                     $this->renderer->setPlugin($function[1]'function'$function);
  1681.                 }
  1682.             }
  1683.  
  1684.             // user defined blocks
  1685.             foreach ($this->smarty_block_plugin as $block{
  1686.                 if (!is_array($block)) {
  1687.                     $name str_replace('smarty_block_'''$block);
  1688.                     $this->renderer->setPlugin($name,'block'$block);
  1689.                 else {
  1690.                     $this->renderer->setPlugin($block[1],'block'$block);
  1691.                 }
  1692.             }
  1693.  
  1694.             // user defined prefilters
  1695.             foreach ($this->smarty_prefilter_plugin as $prefilter{
  1696.                 if (!is_array($prefilter)) {
  1697.                     $name str_replace('smarty_prefilter_'''$prefilter);
  1698.                     $this->renderer->setPlugin($name,'prefilter'$prefilter);
  1699.                 else {
  1700.                     $this->renderer->setPlugin($prefilter[1],'prefilter'$prefilter);
  1701.                 }
  1702.             }
  1703.  
  1704.             // user defined postfilters
  1705.             foreach ($this->smarty_postfilter_plugin as $postfilter{
  1706.                 if (!is_array($postfilter)) {
  1707.                     $name str_replace('smarty_postfilter_'''$postfilter);
  1708.                     $this->renderer->setPlugin($name,'postfilter'$postfilter);
  1709.                 else {
  1710.                     $this->renderer->setPlugin($postfilter[1],'postfilter'$postfilter);
  1711.                 }
  1712.             }
  1713.  
  1714.             // user defined outputfilters
  1715.             foreach ($this->smarty_outputfilter_plugin as $outputfilter{
  1716.                 if (!is_array($outputfilter)) {
  1717.                     $name str_replace('smarty_outputfilter_'''$outputfilter);
  1718.                     $this->renderer->setPlugin($name,'outputfilter'$outputfilter);
  1719.                 else {
  1720.                     $this->renderer->setPlugin($outputfilter[1],'outputfilter'$outputfilter);
  1721.                 }
  1722.             }
  1723.         }
  1724.  
  1725.         //テンプレートエンジンのデフォルトの設定
  1726.         $this->_setDefaultTemplateEngine($this->renderer);
  1727.         // }}}
  1728.  
  1729.         return $this->renderer;
  1730.     }
  1731.  
  1732.     /**
  1733.      *  テンプレートエンジンのデフォルト状態を設定する
  1734.      *
  1735.      *  @access protected
  1736.      *  @param  object  Ethna_Renderer  レンダラオブジェクト
  1737.      *  @obsolete
  1738.      */
  1739.     function _setDefaultTemplateEngine(&$renderer)
  1740.     {
  1741.     }
  1742.  
  1743.     /**
  1744.      *  使用言語を設定する
  1745.      *
  1746.      *  将来への拡張のためのみに存在しています。現在は特にオーバーライドの必要はありません。
  1747.      *
  1748.      *  @access protected
  1749.      *  @param  string  $language           言語定義(LANG_JA, LANG_EN...)
  1750.      *  @param  string  $system_encoding    システムエンコーディング名
  1751.      *  @param  string  $client_encoding    クライアントエンコーディング
  1752.      */
  1753.     function _setLanguage($language$system_encoding null$client_encoding null)
  1754.     {
  1755.         $this->language $language;
  1756.         $this->system_encoding $system_encoding;
  1757.         $this->client_encoding $client_encoding;
  1758.  
  1759.         $i18n =$this->getI18N();
  1760.         $i18n->setLanguage($language$system_encoding$client_encoding);
  1761.     }
  1762.  
  1763.     /**
  1764.      *  デフォルト状態での使用言語を取得する
  1765.      *
  1766.      *  @access protected
  1767.      *  @return array   使用言語,システムエンコーディング名,クライアントエンコーディング名
  1768.      */
  1769.     function _getDefaultLanguage()
  1770.     {
  1771.         return array(LANG_JAnullnull);
  1772.     }
  1773.  
  1774.     /**
  1775.      *  デフォルト状態でのゲートウェイを取得する
  1776.      *
  1777.      *  @access protected
  1778.      *  @return int     ゲートウェイ定義(GATEWAY_WWW, GATEWAY_CLI...)
  1779.      */
  1780.     function _getDefaultGateway($gateway)
  1781.     {
  1782.         if (is_null($GLOBALS['_Ethna_gateway']== false{
  1783.             return $GLOBALS['_Ethna_gateway'];
  1784.         }
  1785.         return GATEWAY_WWW;
  1786.     }
  1787.  
  1788.     /**
  1789.      *  ゲートウェイに対応したクラス名のプレフィクスを取得する
  1790.      *
  1791.      *  @access public
  1792.      *  @param  string  $gateway    ゲートウェイ
  1793.      *  @return string  ゲートウェイクラスプレフィクス
  1794.      */
  1795.     function _getGatewayPrefix($gateway null)
  1796.     {
  1797.         $gateway is_null($gateway$this->getGateway($gateway;
  1798.         switch ($gateway{
  1799.         case GATEWAY_WWW:
  1800.             $prefix '';
  1801.             break;
  1802.         case GATEWAY_CLI:
  1803.             $prefix 'Cli';
  1804.             break;
  1805.         case GATEWAY_XMLRPC:
  1806.             $prefix 'Xmlrpc';
  1807.             break;
  1808.         default:
  1809.             $prefix '';
  1810.             break;
  1811.         }
  1812.  
  1813.         return $prefix;
  1814.     }
  1815.  
  1816.     /**
  1817.      *  マネージャクラス名を取得する
  1818.      *
  1819.      *  @access public
  1820.      *  @param  string  $name   マネージャキー
  1821.      *  @return string  マネージャクラス名
  1822.      */
  1823.     function getManagerClassName($name)
  1824.     {
  1825.         return sprintf('%s_%sManager'$this->getAppId()ucfirst($name));
  1826.     }
  1827.  
  1828.     /**
  1829.      *  アプリケーションオブジェクトクラス名を取得する
  1830.      *
  1831.      *  @access public
  1832.      *  @param  string  $name   アプリケーションオブジェクトキー
  1833.      *  @return string  マネージャクラス名
  1834.      */
  1835.     function getObjectClassName($name)
  1836.     {
  1837.         $name preg_replace('/_(.)/e'"strtoupper('\$1')"ucfirst($name));
  1838.         return sprintf('%s_%s'$this->getAppId()$name);
  1839.     }
  1840.  
  1841.     /**
  1842.      *  アクションスクリプトをインクルードする
  1843.      *
  1844.      *  ただし、インクルードしたファイルにクラスが正しく定義されているかどうかは保証しない
  1845.      *
  1846.      *  @access private
  1847.      *  @param  array   $action_obj     アクション定義
  1848.      *  @param  string  $action_name    アクション名
  1849.      */
  1850.     function _includeActionScript($action_obj$action_name)
  1851.     {
  1852.         $class_path $form_path null;
  1853.  
  1854.         $action_dir $this->getActiondir();
  1855.  
  1856.         // class_path属性チェック
  1857.         if (isset($action_obj['class_path'])) {
  1858.             // フルパス指定サポート
  1859.             $tmp_path $action_obj['class_path'];
  1860.             if (Ethna_Util::isAbsolute($tmp_path== false{
  1861.                 $tmp_path $action_dir $tmp_path;
  1862.             }
  1863.  
  1864.             if (file_exists($tmp_path== false{
  1865.                 $this->logger->log(LOG_WARNING'class_path file not found [%s] -> try default'$tmp_path);
  1866.             else {
  1867.                 include_once $tmp_path;
  1868.                 $class_path $tmp_path;
  1869.             }
  1870.         }
  1871.  
  1872.         // デフォルトチェック
  1873.         if (is_null($class_path)) {
  1874.             $class_path $this->getDefaultActionPath($action_name);
  1875.             if (file_exists($action_dir $class_path)) {
  1876.                 include_once $action_dir $class_path;
  1877.             else {
  1878.                 $this->logger->log(LOG_DEBUG'default action file not found [%s] -> try all files'$class_path);
  1879.                 $class_path null;
  1880.             }
  1881.         }
  1882.         
  1883.         // 全ファイルインクルード
  1884.         if (is_null($class_path)) {
  1885.             $this->_includeDirectory($this->getActiondir());
  1886.             return;
  1887.         }
  1888.  
  1889.         // form_path属性チェック
  1890.         if (isset($action_obj['form_path'])) {
  1891.             // フルパス指定サポート
  1892.             $tmp_path $action_obj['form_path'];
  1893.             if (Ethna_Util::isAbsolute($tmp_path== false{
  1894.                 $tmp_path $action_dir $tmp_path;
  1895.             }
  1896.  
  1897.             if ($tmp_path == $class_path{
  1898.                 return;
  1899.             }
  1900.             if (file_exists($tmp_path== false{
  1901.                 $this->logger->log(LOG_WARNING'form_path file not found [%s] -> try default'$tmp_path);
  1902.             else {
  1903.                 include_once $tmp_path;
  1904.                 $form_path $tmp_path;
  1905.             }
  1906.         }
  1907.  
  1908.         // デフォルトチェック
  1909.         if (is_null($form_path)) {
  1910.             $form_path $this->getDefaultFormPath($action_name);
  1911.             if ($form_path == $class_path{
  1912.                 return;
  1913.             }
  1914.             if (file_exists($action_dir $form_path)) {
  1915.                 include_once $action_dir $form_path;
  1916.             else {
  1917.                 $this->logger->log(LOG_DEBUG'default form file not found [%s] -> maybe falling back to default form class'$form_path);
  1918.             }
  1919.         }
  1920.     }
  1921.  
  1922.     /**
  1923.      *  ビュースクリプトをインクルードする
  1924.      *
  1925.      *  ただし、インクルードしたファイルにクラスが正しく定義されているかどうかは保証しない
  1926.      *
  1927.      *  @access private
  1928.      *  @param  array   $forward_obj    遷移定義
  1929.      *  @param  string  $forward_name   遷移名
  1930.      */
  1931.     function _includeViewScript($forward_obj$forward_name)
  1932.     {
  1933.         $view_dir $this->getViewdir();
  1934.  
  1935.         // view_path属性チェック
  1936.         if (isset($forward_obj['view_path'])) {
  1937.             // フルパス指定サポート
  1938.             $tmp_path $forward_obj['view_path'];
  1939.             if (Ethna_Util::isAbsolute($tmp_path== false{
  1940.                 $tmp_path $view_dir $tmp_path;
  1941.             }
  1942.  
  1943.             if (file_exists($tmp_path== false{
  1944.                 $this->logger->log(LOG_WARNING'view_path file not found [%s] -> try default'$tmp_path);
  1945.             else {
  1946.                 include_once $tmp_path;
  1947.                 return;
  1948.             }
  1949.         }
  1950.  
  1951.         // デフォルトチェック
  1952.         $view_path $this->getDefaultViewPath($forward_name);
  1953.         if (file_exists($view_dir $view_path)) {
  1954.             include_once $view_dir $view_path;
  1955.             return;
  1956.         else {
  1957.             $this->logger->log(LOG_DEBUG'default view file not found [%s]'$view_path);
  1958.             $view_path null;
  1959.         }
  1960.     }
  1961.  
  1962.     /**
  1963.      *  ディレクトリ以下の全てのスクリプトをインクルードする
  1964.      *
  1965.      *  @access private
  1966.      */
  1967.     function _includeDirectory($dir)
  1968.     {
  1969.         $ext "." $this->ext['php'];
  1970.         $ext_len strlen($ext);
  1971.  
  1972.         if (is_dir($dir== false{
  1973.             return;
  1974.         }
  1975.  
  1976.         $dh opendir($dir);
  1977.         if ($dh{
  1978.             while (($file readdir($dh)) !== false{
  1979.                 if ($file != '.' && $file != '..' && is_dir("$dir/$file")) {
  1980.                     $this->_includeDirectory("$dir/$file");
  1981.                 }
  1982.                 if (substr($file-$ext_len$ext_len!= $ext{
  1983.                     continue;
  1984.                 }
  1985.                 include_once $dir '/' $file;
  1986.             }
  1987.         }
  1988.         closedir($dh);
  1989.     }
  1990.  
  1991.     /**
  1992.      *  設定ファイルのDSN定義から使用するデータを再構築する(スレーブアクセス分岐等)
  1993.      *
  1994.      *  DSNの定義方法(デフォルト:設定ファイル)を変えたい場合はここをオーバーライドする
  1995.      *
  1996.      *  @access protected
  1997.      *  @return array   DSN定義(array('DBキー1' => 'dsn1', 'DBキー2' => 'dsn2', ...))
  1998.      */
  1999.     function _prepareDSN()
  2000.     {
  2001.         $r array();
  2002.  
  2003.         foreach ($this->db as $key => $value{
  2004.             $config_key "dsn";
  2005.             if ($key != ""{
  2006.                 $config_key .= "_$key";
  2007.             }
  2008.             $dsn $this->config->get($config_key);
  2009.             if (is_array($dsn)) {
  2010.                 // 種別1つにつき複数DSNが定義されている場合はアクセス分岐
  2011.                 $dsn $this->_selectDSN($key$dsn);
  2012.             }
  2013.             $r[$key$dsn;
  2014.         }
  2015.         return $r;
  2016.     }
  2017.  
  2018.     /**
  2019.      *  DSNのアクセス分岐を行う
  2020.      *  
  2021.      *  スレーブサーバへの振分け処理(デフォルト:ランダム)を変更したい場合はこのメソッドをオーバーライドする
  2022.      *
  2023.      *  @access protected
  2024.      *  @param  string  $type       DB種別
  2025.      *  @param  array   $dsn_list   DSN一覧
  2026.      *  @return string  選択されたDSN
  2027.      */
  2028.     function _selectDSN($type$dsn_list)
  2029.     {
  2030.         if (is_array($dsn_list== false{
  2031.             return $dsn_list;
  2032.         }
  2033.  
  2034.         // デフォルト:ランダム
  2035.         list($usec$secexplode(' 'microtime());
  2036.         mt_srand($sec ((float) $usec 100000));
  2037.         $n mt_rand(0count($dsn_list)-1);
  2038.         
  2039.         return $dsn_list[$n];
  2040.     }
  2041.  
  2042.     /**
  2043.      *  Ethnaマネージャを設定する
  2044.      *
  2045.      *  不要な場合は空のメソッドとしてオーバーライドしてもよい
  2046.      *
  2047.      *  @access protected
  2048.      */
  2049.     function _activateEthnaManager()
  2050.     {
  2051.         if ($this->config->get('debug'== false{
  2052.             return;
  2053.         }
  2054.  
  2055.         require_once ETHNA_BASE '/class/Ethna_InfoManager.php';
  2056.         
  2057.         // see if we have simpletest
  2058.         if (file_exists_ex('simpletest/unit_tester.php'true)) {
  2059.             require_once ETHNA_BASE '/class/Ethna_UnitTestManager.php';
  2060.         }
  2061.  
  2062.         // action設定
  2063.         $this->action['__ethna_info__'array(
  2064.             'form_name' =>  'Ethna_Form_Info',
  2065.             'form_path' =>  sprintf('%s/class/Action/Ethna_Action_Info.php'ETHNA_BASE),
  2066.             'class_name' => 'Ethna_Action_Info',
  2067.             'class_path' => sprintf('%s/class/Action/Ethna_Action_Info.php'ETHNA_BASE),
  2068.         );
  2069.  
  2070.         // forward設定
  2071.         $this->forward['__ethna_info__'array(
  2072.             'forward_path'  => sprintf('%s/tpl/info.tpl'ETHNA_BASE),
  2073.             'view_name'     => 'Ethna_View_Info',
  2074.             'view_path'     => sprintf('%s/class/View/Ethna_View_Info.php'ETHNA_BASE),
  2075.         );
  2076.         
  2077.         
  2078.         // action設定
  2079.         $this->action['__ethna_unittest__'array(
  2080.             'form_name' =>  'Ethna_Form_UnitTest',
  2081.             'form_path' =>  sprintf('%s/class/Action/Ethna_Action_UnitTest.php'ETHNA_BASE),
  2082.             'class_name' => 'Ethna_Action_UnitTest',
  2083.             'class_path' => sprintf('%s/class/Action/Ethna_Action_UnitTest.php'ETHNA_BASE),
  2084.         );
  2085.  
  2086.         // forward設定
  2087.         $this->forward['__ethna_unittest__'array(
  2088.             'forward_path'  => sprintf('%s/tpl/unittest.tpl'ETHNA_BASE),
  2089.             'view_name'     => 'Ethna_View_UnitTest',
  2090.             'view_path'     => sprintf('%s/class/View/Ethna_View_UnitTest.php'ETHNA_BASE),
  2091.         );
  2092.  
  2093.     }
  2094.  
  2095.     /**
  2096.      *  Ethnaマネージャが実行可能かをチェックする
  2097.      *
  2098.      *  Ethnaマネージャを実行するよう指示されているにも関わらず、
  2099.      *  debug が trueでない場合は実行を停止する。
  2100.      *
  2101.      *  @access private
  2102.      */
  2103.     function _ethnaManagerEnabledCheck($action_name)
  2104.     {
  2105.         if ($this->config->get('debug'== false
  2106.          && ($action_name == '__ethna_info__' || $action_name == '__ethna_unittest__')) {
  2107.             $this->ethnaManagerCheckErrorMsg($action_name);
  2108.             exit(0);
  2109.         }
  2110.     }
  2111.  
  2112.     /**
  2113.      *  Ethnaマネージャが実行不能な場合のエラーメッセージを
  2114.      *  表示する。運用上の都合でこのメッセージを出力したくない
  2115.      *  場合は、このメソッドをオーバーライドせよ
  2116.      *
  2117.      *  @access protected
  2118.      */
  2119.      function ethnaManagerCheckErrorMsg($action_name)
  2120.      {
  2121.          $appid strtolower($this->getAppId());
  2122.          $run_action ($action_name == '__ethna_info__')
  2123.                      ? ' show Application Info List '
  2124.                      : ' run Unit Test ';
  2125.          echo "Ethna cannot {$run_action} under your application setting.<br>";
  2126.          echo "HINT: You must set {$appid}/etc/{$appid}-ini.php debug setting 'true'.<br>";
  2127.          echo "<br>";
  2128.          echo "In {$appid}-ini.php, please set as follows :<br><br>";
  2129.          echo "\$config = array ( 'debug' => true, );";
  2130.      
  2131.  
  2132.     /**
  2133.      *  CLI実行中フラグを取得する
  2134.      *
  2135.      *  @access public
  2136.      *  @return bool    CLI実行中フラグ
  2137.      *  @obsolete
  2138.      */
  2139.     function getCLI()
  2140.     {
  2141.         return $this->gateway == GATEWAY_CLI true false;
  2142.     }
  2143.  
  2144.     /**
  2145.      *  CLI実行中フラグを設定する
  2146.      *
  2147.      *  @access public
  2148.      *  @param  bool    CLI実行中フラグ
  2149.      *  @obsolete
  2150.      */
  2151.     function setCLI($cli)
  2152.     {
  2153.         $this->gateway $cli GATEWAY_CLI $this->_getDefaultGateway();
  2154.     }
  2155. }
  2156. // }}}
  2157.  
  2158. /**
  2159.  *  XMLRPCゲートウェイのスタブクラス
  2160.  *
  2161.  *  @access     public
  2162.  */
  2163. function _Ethna_XmlrpcGateway($method_stub$param)
  2164. {
  2165.     $ctl =Ethna_Controller::getInstance();
  2166.     $method $ctl->getXmlrpcMethodName();
  2167.     $r $ctl->trigger_XMLRPC($method$param);
  2168.     if (Ethna::isError($r)) {
  2169.         return array(
  2170.             'faultCode' => $r->getCode(),
  2171.             'faultString' => $r->getMessage(),
  2172.         );
  2173.     }
  2174.     return $r;
  2175. }
  2176. ?>

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