Source for file Controller.php

Documentation is available at Controller.php

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

Documentation generated on Fri, 11 Nov 2011 03:57:54 +0900 by phpDocumentor 1.4.3