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

Documentation generated on Fri, 11 Nov 2011 03:59:35 +0900 by phpDocumentor 1.4.3