PageRenderTime 60ms CodeModel.GetById 14ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 1ms

/extras/installer-ftp/lib/Curaga/class/Ethna_Controller.php

http://xoopscube-modules.googlecode.com/
PHP | 2212 lines | 1123 code | 244 blank | 845 comment | 224 complexity | 1eece36e5866764e1feac81ff40a5825 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2// vim: foldmethod=marker
   3/**
   4 *  Ethna_Controller.php
   5 *
   6 *  @author     Masaki Fujimoto <fujimoto@php.net>
   7 *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
   8 *  @package    Ethna
   9 *  @version    $Id: Ethna_Controller.php 866 2009-06-17 17:01:20Z mumumu-org $
  10 */
  11
  12// {{{ Ethna_Controller
  13/**
  14 *  ?????????
  15 *
  16 *  @todo       gateway?switch???????????
  17 *
  18 *  @author     Masaki Fujimoto <fujimoto@php.net>
  19 *  @access     public
  20 *  @package    Ethna
  21 */
  22class Ethna_Controller
  23{
  24    /**#@+
  25     *  @access private
  26     */
  27
  28    /** @var    string      ????????ID */
  29    var $appid = 'ETHNA';
  30
  31    /** @var    string      ????????????????? */
  32    var $base = '';
  33
  34    /** @var    string      ???????????URL */
  35    var $url = '';
  36
  37    /** @var    string      ????????DSN(Data Source Name) */
  38    var $dsn;
  39
  40    /** @var    array       ?????????????? */
  41    var $directory = array();
  42
  43    /** @var    array       ??????????????(?????) */
  44    var $directory_default = array(
  45        'action'        => 'app/action',
  46        'action_cli'    => 'app/action_cli',
  47        'action_xmlrpc' => 'app/action_xmlrpc',
  48        'app'           => 'app',
  49        'plugin'        => 'app/plugin',
  50        'bin'           => 'bin',
  51        'etc'           => 'etc',
  52        'filter'        => 'app/filter',
  53        'locale'        => 'locale',
  54        'log'           => 'log',
  55        'plugins'       => array(),
  56        'template'      => 'template',
  57        'template_c'    => 'tmp',
  58        'tmp'           => 'tmp',
  59        'view'          => 'app/view',
  60        'www'           => 'www',
  61        'test'          => 'app/test',
  62    );
  63
  64    /** @var    array       DB?????? */
  65    var $db = array(
  66        ''              => DB_TYPE_RW,
  67    );
  68
  69    /** @var    array       ????? */
  70    var $ext = array(
  71        'php'           => 'php',
  72        'tpl'           => 'tpl',
  73    );
  74
  75    /** @var    array       ????? */
  76    var $class = array();
  77
  78    /** @var    array       ?????(?????) */
  79    var $class_default = array(
  80        'class'         => 'Ethna_ClassFactory',
  81        'backend'       => 'Ethna_Backend',
  82        'config'        => 'Ethna_Config',
  83        'db'            => 'Ethna_DB',
  84        'error'         => 'Ethna_ActionError',
  85        'form'          => 'Ethna_ActionForm',
  86        'i18n'          => 'Ethna_I18N',
  87        'logger'        => 'Ethna_Logger',
  88        'plugin'        => 'Ethna_Plugin',
  89        'renderer'      => 'Ethna_Renderer_Smarty',
  90        'session'       => 'Ethna_Session',
  91        'sql'           => 'Ethna_AppSQL',
  92        'view'          => 'Ethna_ViewClass',
  93        'url_handler'   => 'Ethna_UrlHandler',
  94    );
  95
  96    /** @var    array       ?????? */
  97    var $filter = array(
  98    );
  99
 100    /** @var    string      ???????? */
 101    var $locale;
 102
 103    /** @var    string      ????????????? */
 104    var $system_encoding;
 105
 106    /** @var    string      ??????????????? */
 107    /**                     ??????????????????  */
 108    var $client_encoding;
 109
 110    /** @var    string  ???????????? */
 111    var $action_name;
 112
 113    /** @var    string  ??????XMLRPC????? */
 114    var $xmlrpc_method_name;
 115
 116    /** @var    array   forward?? */
 117    var $forward = array();
 118
 119    /** @var    array   ??????forward?? */
 120    var $forward_default = array(
 121        '403' => array( 'view_name' => 'Ethna_View_403',),
 122        '404' => array( 'view_name' => 'Ethna_View_404',),
 123        '500' => array( 'view_name' => 'Ethna_View_500',), 
 124        'json' => array( 'view_name' => 'Ethna_View_Json',),
 125        'redirect' => array( 'view_name' => 'Ethna_View_Redirect',),
 126    );
 127
 128    /** @var    array   action?? */
 129    var $action = array();
 130
 131    /** @var    array   action(CLI)?? */
 132    var $action_cli = array();
 133
 134    /** @var    array   action(XMLRPC)?? */
 135    var $action_xmlrpc = array();
 136
 137    /** @var    array   ??????????????? */
 138    var $manager = array();
 139
 140    /** @var    object  ????? */
 141    var $renderer = null;
 142
 143    /** @var    array   ?????????(Ethna_Filter?????????) */
 144    var $filter_chain = array();
 145
 146    /** @var    object  Ethna_ClassFactory  ?????????????? */
 147    var $class_factory = null;
 148
 149    /** @var    object  Ethna_ActionForm    ?????????? */
 150    var $action_form = null;
 151
 152    /** @var    object  Ethna_View          ????????? */
 153    var $view = null;
 154
 155    /** @var    object  Ethna_Config        ???????? */
 156    var $config = null;
 157
 158    /** @var    object  Ethna_Logger        ???????? */
 159    var $logger = null;
 160
 161    /** @var    object  Ethna_Plugin        ??????????? */
 162    var $plugin = null;
 163
 164    /** @var    string  ????????????(www/cli/rest/xmlrpc/soap...) */
 165    var $gateway = GATEWAY_WWW;
 166
 167    /**#@-*/
 168
 169
 170    /**
 171     *  Ethna_Controller???????????
 172     *
 173     *  @access     public
 174     */
 175    function Ethna_Controller($gateway = GATEWAY_WWW)
 176    {
 177        $GLOBALS['_Ethna_controller'] =& $this;
 178        if ($this->base === "") {
 179            // Ethna???????BASE??????????????
 180            if (defined('BASE')) {
 181                $this->base = BASE;
 182            }
 183        }
 184
 185        $this->gateway = $gateway;
 186
 187        // ?????????????
 188        foreach ($this->class_default as $key => $val) {
 189            if (isset($this->class[$key]) == false) {
 190                $this->class[$key] = $val;
 191            }
 192        }
 193
 194        // ????????????????
 195        foreach ($this->directory_default as $key => $val) {
 196            if (isset($this->directory[$key]) == false) {
 197                $this->directory[$key] = $val;
 198            }
 199        }
 200
 201        // ?????????????????
 202        $class_factory = $this->class['class'];
 203        $this->class_factory =& new $class_factory($this, $this->class);
 204
 205        // ??????????
 206        Ethna::setErrorCallback(array(&$this, 'handleError'));
 207
 208        // ??????????(????->????)
 209        foreach ($this->directory as $key => $value) {
 210            if ($key == 'plugins') {
 211                // Smarty???????????????????
 212                $tmp = array();
 213                foreach (to_array($value) as $elt) {
 214                    if (Ethna_Util::isAbsolute($elt) == false) {
 215                        $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
 216                    }
 217                }
 218                $this->directory[$key] = $tmp;
 219            } else {
 220                if (Ethna_Util::isAbsolute($value) == false) {
 221                    $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
 222                }
 223            }
 224        }
 225
 226        // ?????????
 227        // ?????????????
 228        $this->forward = $this->forward + $this->forward_default;
 229
 230        // ????
 231        // ????????????????????????????
 232        // ?????????=???????????????)
 233        //
 234        // @see Ethna_Controller#_getDefaultLanguage
 235        list($this->locale, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
 236        if (mb_enabled()) {
 237            mb_internal_encoding($this->client_encoding);
 238            mb_regex_encoding($this->client_encoding);
 239        }
 240        $this->config =& $this->getConfig();
 241        $this->dsn = $this->_prepareDSN();
 242        $this->url = $this->config->get('url');
 243
 244        // ??????????????
 245        $this->plugin =& $this->getPlugin();
 246
 247        //// assert (experimental)
 248        //if ($this->config->get('debug') === false) {
 249        //    ini_set('assert.active', 0);
 250        //}
 251
 252        // ??????
 253        $this->logger =& $this->getLogger();
 254        $this->plugin->setLogger($this->logger);
 255        $this->logger->begin();
 256
 257        // Ethna???????
 258        $this->_activateEthnaManager();
 259    }
 260
 261    /**
 262     *  ?????????????????????
 263     *
 264     *  @access protected
 265     */
 266    function end()
 267    {
 268        //  ??????????????????
 269        $this->logger->end();
 270    }
 271
 272    /**
 273     *  (????????)????????????????
 274     *
 275     *  @access public
 276     *  @return object  Ethna_Controller    ?????????????
 277     *  @static
 278     */
 279    function &getInstance()
 280    {
 281        if (isset($GLOBALS['_Ethna_controller'])) {
 282            return $GLOBALS['_Ethna_controller'];
 283        } else {
 284            $_ret_object = null;
 285            return $_ret_object;
 286        }
 287    }
 288
 289    /**
 290     *  ????????ID???
 291     *
 292     *  @access public
 293     *  @return string  ????????ID
 294     */
 295    function getAppId()
 296    {
 297        return ucfirst(strtolower($this->appid));
 298    }
 299
 300    /**
 301     *  ????????ID???????
 302     *
 303     *  @access public
 304     *  @param  string  $id     ????????ID
 305     *  @return mixed   true:OK Ethna_Error:NG
 306     *  @static
 307     */
 308    function &checkAppId($id)
 309    {
 310        $true = true;
 311        if (strcasecmp($id, 'ethna') === 0
 312            || strcasecmp($id, 'app') === 0) {
 313            return Ethna::raiseError("Application Id [$id] is reserved\n");
 314        }
 315
 316        //    ????????ID??????prefix???????
 317        //    ??????????????
 318        //    @see http://www.php.net/manual/en/language.variables.php
 319        if (preg_match('/^[a-zA-Z][a-zA-Z0-9]*$/', $id) === 0) {
 320            $msg = (preg_match('/^[0-9]$/', $id[0]))
 321                 ? "Application ID must NOT start with Number.\n"
 322                 : "Only Numeric(0-9) and Alphabetical(A-Z) is allowed for Application Id\n";
 323            return Ethna::raiseError($msg);
 324        }
 325        return $true;
 326    }
 327
 328    /**
 329     *  ?????????????
 330     *
 331     *  @access public
 332     *  @param  string  $action_name    ??????
 333     *  @return mixed   true:OK Ethna_Error:NG
 334     *  @static
 335     */
 336    function &checkActionName($action_name)
 337    {
 338        $true = true;
 339        if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
 340                       $action_name) === 0) {
 341            return Ethna::raiseError("invalid action name [$action_name]");
 342        }
 343        return $true;
 344    }
 345
 346    /**
 347     *  ???????????
 348     *
 349     *  @access public
 350     *  @param  string  $view_name    ????
 351     *  @return mixed   true:OK Ethna_Error:NG
 352     *  @static
 353     */
 354    function &checkViewName($view_name)
 355    {
 356        $true = true;
 357        if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
 358                       $view_name) === 0) {
 359            return Ethna::raiseError("invalid view name [$view_name]");
 360        }
 361        return $true;
 362    }
 363
 364    /**
 365     *  DSN???
 366     *
 367     *  @access public
 368     *  @param  string  $db_key DB??
 369     *  @return string  DSN
 370     */
 371    function getDSN($db_key = "")
 372    {
 373        if (isset($this->dsn[$db_key]) == false) {
 374            return null;
 375        }
 376        return $this->dsn[$db_key];
 377    }
 378
 379    /**
 380     *  DSN??????????
 381     *
 382     *  @access public
 383     *  @param  string  $db_key DB??
 384     *  @return bool    true:persistent false:non-persistent(????????)
 385     */
 386    function getDSN_persistent($db_key = "")
 387    {
 388        $key = sprintf("dsn%s_persistent", $db_key == "" ? "" : "_$db_key");
 389
 390        $dsn_persistent = $this->config->get($key);
 391        if (is_null($dsn_persistent)) {
 392            return false;
 393        }
 394        return $dsn_persistent;
 395    }
 396
 397    /**
 398     *  DB?????
 399     *
 400     *  @access public
 401     *  @param  string  $db_key DB??("", "r", "rw", "default", "blog_r"...)
 402     *  @return string  $db_key?????DB????(????????null)
 403     */
 404    function getDBType($db_key = null)
 405    {
 406        if (is_null($db_key)) {
 407            // ?????
 408            return $this->db;
 409        }
 410
 411        if (isset($this->db[$db_key]) == false) {
 412            return null;
 413        }
 414        return $this->db[$db_key];
 415    }
 416
 417    /**
 418     *  ???????????URL???
 419     *
 420     *  @access public
 421     *  @return string  ???????????URL
 422     */
 423    function getURL()
 424    {
 425        return $this->url;
 426    }
 427
 428    /**
 429     *  ????????????????????
 430     *
 431     *  @access public
 432     *  @return string  ?????????????????
 433     */
 434    function getBasedir()
 435    {
 436        return $this->base;
 437    }
 438
 439    /**
 440     *  ?????????/??????????????????????
 441     *  ??????? [appid]/template/ja_JP/ (ja_JP??????)
 442     *  ?????? _getDefaultLanguage ???????
 443     *
 444     *  @access public
 445     *  @return string  ????????????
 446     *  @see    Ethna_Controller#_getDefaultLanguage
 447     */
 448    function getTemplatedir()
 449    {
 450        $template = $this->getDirectory('template');
 451
 452        // ?????????
 453        // _getDerfaultLanguage?????????????????????
 454        // ??????????????????????????
 455        if (!empty($this->locale)) {
 456            $template .= '/' . $this->locale;
 457        }
 458
 459        return $template;
 460    }
 461
 462    /**
 463     *  ?????????????????
 464     *
 465     *  @access public
 466     *  @return string  ???????????
 467     */
 468    function getActiondir($gateway = null)
 469    {
 470        $key = 'action';
 471        $gateway = is_null($gateway) ? $this->getGateway() : $gateway;
 472        switch ($gateway) {
 473        case GATEWAY_WWW:
 474            $key = 'action';
 475            break;
 476        case GATEWAY_CLI:
 477            $key = 'action_cli';
 478            break;
 479        case GATEWAY_XMLRPC:
 480            $key = 'action_xmlrpc';
 481            break;
 482        }
 483
 484        return (empty($this->directory[$key]) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory[$key] . "/"));
 485    }
 486
 487    /**
 488     *  ???????????????
 489     *
 490     *  @access public
 491     *  @return string  ?????????
 492     */
 493    function getViewdir()
 494    {
 495        return (empty($this->directory['view']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['view'] . "/"));
 496    }
 497
 498    /**
 499     *  (action,view???)?????????????????????
 500     *
 501     *  @access public
 502     *  @return string  ???????????????
 503     */
 504    function getTestdir()
 505    {
 506        return (empty($this->directory['test']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['test'] . "/"));
 507    }
 508
 509    /**
 510     *  ???????????????????
 511     *
 512     *  @access public
 513     *  @param  string  $key    ?????????("tmp", "template"...)
 514     *  @return string  $key???????????????????(????????null)
 515     */
 516    function getDirectory($key)
 517    {
 518        if (isset($this->directory[$key]) == false) {
 519            return null;
 520        }
 521        return $this->directory[$key];
 522    }
 523
 524    /**
 525     *  ????????????????
 526     *
 527     *  @access public
 528     *  @param  string  $key    ??????("php", "tpl"...)
 529     *  @return string  $key????????(????????null)
 530     */
 531    function getExt($key)
 532    {
 533        if (isset($this->ext[$key]) == false) {
 534            return null;
 535        }
 536        return $this->ext[$key];
 537    }
 538
 539    /**
 540     *  ???????????????????(R)
 541     *
 542     *  @access public
 543     *  @return object  Ethna_ClassFactory  ??????????????
 544     */
 545    function &getClassFactory()
 546    {
 547        return $this->class_factory;
 548    }
 549
 550    /**
 551     *  ???????????????????
 552     *
 553     *  @access public
 554     *  @return object  Ethna_ActionError   ??????????????
 555     */
 556    function &getActionError()
 557    {
 558        return $this->class_factory->getObject('error');
 559    }
 560
 561    /**
 562     *  ????????????????????
 563     *
 564     *  @access public
 565     *  @return object  Ethna_ActionForm    ???????????????
 566     */
 567    function &getActionForm()
 568    {
 569        // ????????????????????
 570        return $this->action_form;
 571    }
 572
 573    /**
 574     *  ??????????????
 575     *
 576     *  @access public
 577     *  @return object  Ethna_View          ?????????
 578     */
 579    function &getView()
 580    {
 581        // ????????????????????
 582        return $this->view;
 583    }
 584
 585    /**
 586     *  backend???????????
 587     *
 588     *  @access public
 589     *  @return object  Ethna_Backend   backend??????
 590     */
 591    function &getBackend()
 592    {
 593        return $this->class_factory->getObject('backend');
 594    }
 595
 596    /**
 597     *  ?????????????
 598     *
 599     *  @access public
 600     *  @return object  Ethna_Config    ????????
 601     */
 602    function &getConfig()
 603    {
 604        return $this->class_factory->getObject('config');
 605    }
 606
 607    /**
 608     *  i18n???????????(R)
 609     *
 610     *  @access public
 611     *  @return object  Ethna_I18N  i18n??????
 612     */
 613    function &getI18N()
 614    {
 615        return $this->class_factory->getObject('i18n');
 616    }
 617
 618    /**
 619     *  ?????????????
 620     *
 621     *  @access public
 622     *  @return object  Ethna_Logger        ????????
 623     */
 624    function &getLogger()
 625    {
 626        return $this->class_factory->getObject('logger');
 627    }
 628
 629    /**
 630     *  ????????????????
 631     *
 632     *  @access public
 633     *  @return object  Ethna_Session       ???????????
 634     */
 635    function &getSession()
 636    {
 637        return $this->class_factory->getObject('session');
 638    }
 639
 640    /**
 641     *  SQL???????????
 642     *
 643     *  @access public
 644     *  @return object  Ethna_AppSQL    SQL??????
 645     */
 646    function &getSQL()
 647    {
 648        return $this->class_factory->getObject('sql');
 649    }
 650
 651    /**
 652     *  ????????????????
 653     *
 654     *  @access public
 655     *  @return object  Ethna_Plugin    ???????????
 656     */
 657    function &getPlugin()
 658    {
 659        return $this->class_factory->getObject('plugin');
 660    }
 661
 662    /**
 663     *  URL???????????????
 664     *
 665     *  @access public
 666     *  @return object  Ethna_UrlHandler    URL??????????
 667     */
 668    function &getUrlHandler()
 669    {
 670        return $this->class_factory->getObject('url_handler');
 671    }
 672
 673    /**
 674     *  ??????????
 675     *
 676     *  @access public
 677     *  @return array   ???????
 678     *  @obsolete
 679     */
 680    function getManagerList()
 681    {
 682        return $this->manager;
 683    }
 684
 685    /**
 686     *  ?????????????
 687     *
 688     *  @access public
 689     *  @return string  ??????????
 690     */
 691    function getCurrentActionName()
 692    {
 693        return $this->action_name;
 694    }
 695
 696    /**
 697     *  ????XMLRPC????????
 698     *
 699     *  @access public
 700     *  @return string  ????XMLRPC?????
 701     */
 702    function getXmlrpcMethodName()
 703    {
 704        return $this->xmlrpc_method_name;
 705    }
 706
 707    /**
 708     *  ????????????????
 709     *
 710     *  @access public
 711     *  @return array   ?????(e.x ja_JP, en_US ?),
 712     *                  ?????????????,
 713     *                  ??????????????? ???
 714     *                  (???????ll_cc ????ll = ????? cc = ????)
 715     *  @see http://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html
 716     */
 717    function getLanguage()
 718    {
 719        return array($this->locale, $this->system_encoding, $this->client_encoding);
 720    }
 721
 722    /**
 723     *  ???????????(R)
 724     *
 725     *  @access public
 726     *  @return string  ?????(e.x ja_JP, en_US ?),
 727     *                  (???????ll_cc ????ll = ????? cc = ????)
 728     */
 729    function getLocale()
 730    {
 731        return $this->locale;
 732    }
 733
 734    /**
 735     *  ???????????(W)
 736     *
 737     *  @access public
 738     *  @param $locale ?????(e.x ja_JP, en_US ?),
 739     *                 (???????ll_cc ????ll = ????? cc = ????)
 740     */
 741    function setLocale($locale)
 742    {
 743        $this->locale = $locale;
 744        $i18n =& $this->getI18N();
 745        $i18n->setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
 746    }
 747
 748    /**
 749     *  ?????????????????????(R)
 750     *
 751     *  @access public
 752     *  @return string  $client_encoding ???????????????
 753     */
 754    function getClientEncoding()
 755    {
 756        return $this->client_encoding;
 757    }
 758
 759    /**
 760     *  ?????????????????????(W)
 761     *
 762     *  @access public
 763     *  @param  string  $client_encoding ???????????????
 764     */
 765    function setClientEncoding($client_encoding)
 766    {
 767        $this->client_encoding = $client_encoding;
 768        $i18n =& $this->getI18N();
 769        $i18n->setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
 770    }
 771
 772    /**
 773     *  ???????????
 774     *
 775     *  @access public
 776     */
 777    function getGateway()
 778    {
 779        return $this->gateway;
 780    }
 781
 782    /**
 783     *  ??????????????
 784     *
 785     *  @access public
 786     */
 787    function setGateway($gateway)
 788    {
 789        $this->gateway = $gateway;
 790    }
 791
 792    /**
 793     *  ?????????????????
 794     *
 795     *  @access public
 796     *  @param  string  $class_name     ???????????????????
 797     *  @param  mixed   $action_name    ?????????(???)
 798     *  @param  mixed   $fallback_action_name   ????????????????????????????(???)
 799     *  @static
 800     */
 801    function main($class_name, $action_name = "", $fallback_action_name = "")
 802    {
 803        $c =& new $class_name;
 804        $c->trigger($action_name, $fallback_action_name);
 805        $c->end();
 806    }
 807
 808    /**
 809     *  CLI?????????????????
 810     *
 811     *  @access public
 812     *  @param  string  $class_name     ???????????????????
 813     *  @param  string  $action_name    ??????????
 814     *  @param  bool    $enable_filter  ??????????????????
 815     *  @static
 816     */
 817    function main_CLI($class_name, $action_name, $enable_filter = true)
 818    {
 819        $c =& new $class_name(GATEWAY_CLI);
 820        $c->action_cli[$action_name] = array();
 821        $c->trigger($action_name, "", $enable_filter);
 822        $c->end();
 823    }
 824
 825    /**
 826     *  XMLRPC?????????????????
 827     *
 828     *  @access public
 829     *  @static
 830     */
 831    function main_XMLRPC($class_name)
 832    {
 833        if (extension_loaded('xmlrpc') == false) {
 834            die("xmlrpc extension is required to enable this gateway");
 835        }
 836
 837        $c =& new $class_name(GATEWAY_XMLRPC);
 838        $c->trigger("", "", false);
 839        $c->end();
 840    }
 841
 842    /**
 843     *  SOAP?????????????????
 844     *
 845     *  @access public
 846     *  @param  string  $class_name     ???????????????????
 847     *  @param  mixed   $action_name    ?????????(???)
 848     *  @param  mixed   $fallback_action_name   ????????????????????????????(???)
 849     *  @static
 850     */
 851    function main_SOAP($class_name, $action_name = "", $fallback_action_name = "")
 852    {
 853        $c =& new $class_name(GATEWAY_SOAP);
 854        $c->trigger($action_name, $fallback_action_name);
 855        $c->end();
 856    }
 857
 858    /**
 859     *  ???????????????
 860     *
 861     *  @access public
 862     *  @param  mixed   $default_action_name    ?????????
 863     *  @param  mixed   $fallback_action_name   ?????????????????????????????
 864     *  @param  bool    $enable_filter  ??????????????????
 865     *  @return mixed   0:???? Ethna_Error:???
 866     */
 867    function trigger($default_action_name = "", $fallback_action_name = "", $enable_filter = true)
 868    {
 869        // ????????
 870        if ($enable_filter) {
 871            $this->_createFilterChain();
 872        }
 873
 874        // ???????
 875        for ($i = 0; $i < count($this->filter_chain); $i++) {
 876            $r = $this->filter_chain[$i]->preFilter();
 877            if (Ethna::isError($r)) {
 878                return $r;
 879            }
 880        }
 881
 882        // trigger
 883        switch ($this->getGateway()) {
 884        case GATEWAY_WWW:
 885            $this->_trigger_WWW($default_action_name, $fallback_action_name);
 886            break;
 887        case GATEWAY_CLI:
 888            $this->_trigger_CLI($default_action_name);
 889            break;
 890        case GATEWAY_XMLRPC:
 891            $this->_trigger_XMLRPC();
 892            break;
 893        case GATEWAY_SOAP:
 894            $this->_trigger_SOAP();
 895            break;
 896        }
 897
 898        // ???????
 899        for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
 900            $r = $this->filter_chain[$i]->postFilter();
 901            if (Ethna::isError($r)) {
 902                return $r;
 903            }
 904        }
 905    }
 906
 907    /**
 908     *  ???????????????(WWW)
 909     *
 910     *  ??$default_action_name??????????????????????
 911     *  ??????????????(???????????????????
 912     *  ?????????????????????????)
 913     *
 914     *  @access private
 915     *  @param  mixed   $default_action_name    ?????????
 916     *  @param  mixed   $fallback_action_name   ?????????????????????????????
 917     *  @return mixed   0:???? Ethna_Error:???
 918     */
 919    function _trigger_WWW($default_action_name = "", $fallback_action_name = "")
 920    {
 921        // ?????????
 922        $action_name = $this->_getActionName($default_action_name, $fallback_action_name);
 923
 924        // ???????????
 925        $this->_ethnaManagerEnabledCheck($action_name);
 926
 927        // ??????????
 928        $action_obj =& $this->_getAction($action_name);
 929        if (is_null($action_obj)) {
 930            if ($fallback_action_name != "") {
 931                $this->logger->log(LOG_DEBUG, 'undefined action [%s] -> try fallback action [%s]', $action_name, $fallback_action_name);
 932                $action_obj =& $this->_getAction($fallback_action_name);
 933            }
 934            if (is_null($action_obj)) {
 935                return Ethna::raiseError("undefined action [%s]", E_APP_UNDEFINED_ACTION, $action_name);
 936            } else {
 937                $action_name = $fallback_action_name;
 938            }
 939        }
 940
 941        // ????????????
 942        for ($i = 0; $i < count($this->filter_chain); $i++) {
 943            $r = $this->filter_chain[$i]->preActionFilter($action_name);
 944            if ($r != null) {
 945                $this->logger->log(LOG_DEBUG, 'action [%s] -> [%s] by %s', $action_name, $r, get_class($this->filter_chain[$i]));
 946                $action_name = $r;
 947            }
 948        }
 949        $this->action_name = $action_name;
 950
 951        // ????????
 952        $backend =& $this->getBackend();
 953        $session =& $this->getSession();
 954        $session->restore();
 955
 956        // ????????????
 957        $this->_setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
 958
 959        // ????????????
 960        // ??????????????
 961        $form_name = $this->getActionFormName($action_name);
 962        $this->action_form =& new $form_name($this);
 963        $this->action_form->setFormDef_PreHelper();
 964        $this->action_form->setFormVars();
 965        $backend->setActionForm($this->action_form);
 966
 967        // ??????????
 968        $forward_name = $backend->perform($action_name);
 969
 970        // ????????????
 971        for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
 972            $r = $this->filter_chain[$i]->postActionFilter($action_name, $forward_name);
 973            if ($r != null) {
 974                $this->logger->log(LOG_DEBUG, 'forward [%s] -> [%s] by %s', $forward_name, $r, get_class($this->filter_chain[$i]));
 975                $forward_name = $r;
 976            }
 977        }
 978
 979        // ???????????????(?????)
 980        $forward_name_params = $this->_sortForward($action_name, $forward_name);
 981
 982        // View????????????
 983        $preforward_params = array();
 984        if (is_array($forward_name_params)) {
 985            $forward_name = array_shift($forward_name_params);
 986            $preforward_params = $forward_name_params;
 987        }
 988        else {
 989            $forward_name = $forward_name_params;
 990        }
 991
 992        if ($forward_name != null) {
 993            $view_class_name = $this->getViewClassName($forward_name);
 994            $this->view =& new $view_class_name($backend, $forward_name, $this->_getForwardPath($forward_name));
 995            call_user_func_array(array($this->view, 'preforward'), $preforward_params);
 996            $this->view->forward();
 997        }
 998
 999        return 0;
1000    }
1001
1002    /**
1003     *  ???????????????(CLI)
1004     *
1005     *  @access private
1006     *  @param  mixed   $default_action_name    ?????????
1007     *  @return mixed   0:???? Ethna_Error:???
1008     */
1009    function _trigger_CLI($default_action_name = "")
1010    {
1011        return $this->_trigger_WWW($default_action_name);
1012    }
1013
1014    /**
1015     *  ???????????????(XMLRPC)
1016     *
1017     *  @access private
1018     *  @param  mixed   $action_name    ?????????
1019     *  @return mixed   0:???? Ethna_Error:???
1020     */
1021    function _trigger_XMLRPC($action_name = "")
1022    {
1023        // prepare xmlrpc server
1024        $xmlrpc_gateway_method_name = "_Ethna_XmlrpcGateway";
1025        $xmlrpc_server = xmlrpc_server_create();
1026
1027        $method = null;
1028        $param = xmlrpc_decode_request(file_get_contents('php://input'), $method);
1029        $this->xmlrpc_method_name = $method;
1030
1031        $request = xmlrpc_encode_request(
1032            $xmlrpc_gateway_method_name,
1033            $param,
1034            array(
1035                'output_type'   => 'xml',
1036                'verbosity'     => 'pretty',
1037                'escaping'      => array('markup'),
1038                'version'       => 'xmlrpc',
1039                'encoding'      => 'utf-8'
1040            )
1041        );
1042
1043        xmlrpc_server_register_method(
1044            $xmlrpc_server,
1045            $xmlrpc_gateway_method_name,
1046            $xmlrpc_gateway_method_name
1047        );
1048
1049        // send request
1050        $r = xmlrpc_server_call_method(
1051            $xmlrpc_server,
1052            $request,
1053            null,
1054            array(
1055                'output_type'   => 'xml',
1056                'verbosity'     => 'pretty',
1057                'escaping'      => array('markup'),
1058                'version'       => 'xmlrpc',
1059                'encoding'      => 'utf-8'
1060            )
1061        );
1062
1063        header('Content-Length: ' . strlen($r));
1064        header('Content-Type: text/xml; charset=UTF-8');
1065        print $r;
1066    }
1067
1068    /**
1069     *  _trigger_XMLRPC???????????
1070     *
1071     *  @access public
1072     */
1073    function trigger_XMLRPC($method, $param)
1074    {
1075        // ??????????
1076        $action_obj =& $this->_getAction($method);
1077        if (is_null($action_obj)) {
1078            return Ethna::raiseError("undefined xmlrpc method [%s]", E_APP_UNDEFINED_ACTION, $method);
1079        }
1080
1081        // ????????
1082        $backend =& $this->getBackend();
1083
1084        $form_name = $this->getActionFormName($method);
1085        $this->action_form =& new $form_name($this);
1086        $def = $this->action_form->getDef();
1087        $n = 0;
1088        foreach ($def as $key => $value) {
1089            if (isset($param[$n]) == false) {
1090                $this->action_form->set($key, null);
1091            } else {
1092                $this->action_form->set($key, $param[$n]);
1093            }
1094            $n++;
1095        }
1096
1097        // ??????????
1098        $backend->setActionForm($this->action_form);
1099
1100        $session =& $this->getSession();
1101        $session->restore();
1102        $r = $backend->perform($method);
1103
1104        return $r;
1105    }
1106
1107    /**
1108     *  SOAP???????????????
1109     *
1110     *  @access private
1111     */
1112    function _trigger_SOAP()
1113    {
1114        // SOAP???????
1115        $gg =& new Ethna_SOAP_GatewayGenerator();
1116        $script = $gg->generate();
1117        eval($script);
1118
1119        // SOAP???????
1120        $server =& new SoapServer(null, array('uri' => $this->config->get('url')));
1121        $server->setClass($gg->getClassName());
1122        $server->handle();
1123    }
1124
1125    /**
1126     *  ???????
1127     *
1128     *  ???????????????????????????????????
1129     *  (???????????????????????????????
1130     *  ??????????????????????????????
1131     *  ????????)
1132     *
1133     *  @access public
1134     *  @param  object  Ethna_Error     ?????????
1135     */
1136    function handleError(&$error)
1137    {
1138        // ????
1139        list ($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
1140        $message = $error->getMessage();
1141        $this->logger->log($log_level, sprintf("%s [ERROR CODE(%d)]", $message, $error->getCode()));
1142    }
1143
1144    /**
1145     *  ?????????????
1146     *
1147     *  @access public
1148     *  @param  int     $code       ??????
1149     *  @return string  ????????
1150     */
1151    function getErrorMessage($code)
1152    {
1153        $message_list =& $GLOBALS['_Ethna_error_message_list'];
1154        for ($i = count($message_list)-1; $i >= 0; $i--) {
1155            if (array_key_exists($code, $message_list[$i])) {
1156                return $message_list[$i][$code];
1157            }
1158        }
1159        return null;
1160    }
1161
1162    /**
1163     *  ?????????????
1164     *
1165     *  @access private
1166     *  @param  mixed   $default_action_name    ?????????
1167     *  @return string  ??????????
1168     */
1169    function _getActionName($default_action_name, $fallback_action_name)
1170    {
1171        // ??????????????????????
1172        $form_action_name = $this->_getActionName_Form();
1173        $form_action_name = preg_replace('/[^a-z0-9\-_]+/i', '', $form_action_name);
1174        $this->logger->log(LOG_DEBUG, 'form_action_name[%s]', $form_action_name);
1175
1176        // Ethna??????????????????????
1177        if ($form_action_name == "__ethna_info__" ||
1178            $form_action_name == "__ethna_unittest__") {
1179            $form_action_name = "";
1180        }
1181
1182        // ????????????????????????????????????????
1183        if ($form_action_name == "" && count($default_action_name) > 0) {
1184            $tmp = is_array($default_action_name) ? $default_action_name[0] : $default_action_name;
1185            if ($tmp{strlen($tmp)-1} == '*') {
1186                $tmp = substr($tmp, 0, -1);
1187            }
1188            $this->logger->log(LOG_DEBUG, '-> default_action_name[%s]', $tmp);
1189            $action_name = $tmp;
1190        } else {
1191            $action_name = $form_action_name;
1192        }
1193
1194        // ??????????????????????????????????????
1195        if (is_array($default_action_name)) {
1196            if ($this->_isAcceptableActionName($action_name, $default_action_name) == false) {
1197                // ??????????????????$fallback_action_name(or ?????)
1198                $tmp = $fallback_action_name != "" ? $fallback_action_name : $default_action_name[0];
1199                if ($tmp{strlen($tmp)-1} == '*') {
1200                    $tmp = substr($tmp, 0, -1);
1201                }
1202                $this->logger->log(LOG_DEBUG, '-> fallback_action_name[%s]', $tmp);
1203                $action_name = $tmp;
1204            }
1205        }
1206
1207        $this->logger->log(LOG_DEBUG, '<<< action_name[%s] >>>', $action_name);
1208
1209        return $action_name;
1210    }
1211
1212    /**
1213     *  ?????????????????????
1214     *
1215     *  ???????????????????????????????????
1216     *  ???????"action_"??????????"action_"?????????
1217     *  ("action_sample"??"sample")???????????????
1218     *
1219     *  @access protected
1220     *  @return string  ??????????????????
1221     */
1222    function _getActionName_Form()
1223    {
1224        if (isset($_SERVER['REQUEST_METHOD']) == false) {
1225            return null;
1226        }
1227
1228        $url_handler =& $this->getUrlHandler();
1229        if ($_SERVER['REQUEST_METHOD'] == "GET") {
1230            $tmp_vars = $_GET;
1231        } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
1232            $tmp_vars = $_POST;
1233        }
1234
1235        if (empty($_SERVER['URL_HANDLER']) == false) {
1236            $tmp_vars['__url_handler__'] = $_SERVER['URL_HANDLER'];
1237            $tmp_vars['__url_info__'] = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null;
1238            $tmp_vars = $url_handler->requestToAction($tmp_vars);
1239
1240            if ($_SERVER['REQUEST_METHOD'] == "GET") {
1241                $_GET = array_merge($_GET, $tmp_vars);
1242            } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
1243                $_POST = array_merge($_POST, $tmp_vars);
1244            }
1245            $_REQUEST = array_merge($_REQUEST, $tmp_vars);
1246        }
1247
1248        if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
1249            $http_vars =& $_POST;
1250        } else {
1251            $http_vars =& $_GET;
1252        }
1253
1254        // ??????????????????????????
1255        $action_name = $sub_action_name = null;
1256        foreach ($http_vars as $name => $value) {
1257            if ($value == "" || strncmp($name, 'action_', 7) != 0) {
1258                continue;
1259            }
1260
1261            $tmp = substr($name, 7);
1262
1263            // type="image"??
1264            if (preg_match('/_x$/', $name) || preg_match('/_y$/', $name)) {
1265                $tmp = substr($tmp, 0, strlen($tmp)-2);
1266            }
1267
1268            // value="dummy"????????????????
1269            if ($value == "dummy") {
1270                $sub_action_name = $tmp;
1271            } else {
1272                $action_name = $tmp;
1273            }
1274        }
1275        if ($action_name == null) {
1276            $action_name = $sub_action_name;
1277        }
1278
1279        return $action_name;
1280    }
1281
1282    /**
1283     *  ??????????????/HTML?????
1284     *
1285     *  @access public
1286     *  @param  string  $action action to request
1287     *  @param  string  $type   hidden, url...
1288     *  @todo   consider gateway
1289     */
1290    function getActionRequest($action, $type = "hidden")
1291    {
1292        $s = null;
1293        if ($type == "hidden") {
1294            $s = sprintf('<input type="hidden" name="action_%s" value="true" />', htmlspecialchars($action, ENT_QUOTES));
1295        } else if ($type == "url") {
1296            $s = sprintf('action_%s=true', urlencode($action));
1297        }
1298        return $s;
1299    }
1300
1301    /**
1302     *  ????????????????????????????
1303     *
1304     *  @access private
1305     *  @param  string  $action_name    ??????
1306     *  @return array   ???????
1307     */
1308    function &_getAction($action_name, $gateway = null)
1309    {
1310        $action = array();
1311        $gateway = is_null($gateway) ? $this->getGateway() : $gateway;
1312        switch ($gateway) {
1313        case GATEWAY_WWW:
1314            $action =& $this->action;
1315            break;
1316        case GATEWAY_CLI:
1317            $action =& $this->action_cli;
1318            break;
1319        case GATEWAY_XMLRPC:
1320            $action =& $this->action_xmlrpc;
1321            break;
1322        }
1323
1324        $action_obj = array();
1325        if (isset($action[$action_name])) {
1326            $action_obj = $action[$action_name];
1327            if (isset($action_obj['inspect']) && $action_obj['inspect']) {
1328                return $action_obj;
1329            }
1330        } else {
1331            $this->logger->log(LOG_DEBUG, "action [%s] is not defined -> try default", $action_name);
1332        }
1333
1334        // ?????????????????
1335        $this->_includeActionScript($action_obj, $action_name);
1336
1337        // ??????
1338        if (isset($action_obj['class_name']) == false) {
1339            $action_obj['class_name'] = $this->getDefaultActionClass($action_name);
1340        }
1341
1342        if (isset($action_obj['form_name']) == false) {
1343            $action_obj['form_name'] = $this->getDefaultFormClass($action_name);
1344        } else if (class_exists($action_obj['form_name']) == false) {
1345            // ????????????????????????????
1346            $this->logger->log(LOG_WARNING, 'stated form class is not defined [%s]', $action_obj['form_name']);
1347        }
1348
1349        // ???????
1350        if (class_exists($action_obj['class_name']) == false) {
1351            $this->logger->log(LOG_NOTICE, 'action class is not defined [%s]', $action_obj['class_name']);
1352            $_ret_object = null;
1353            return $_ret_object;
1354        }
1355        if (class_exists($action_obj['form_name']) == false) {
1356            // ???????????????
1357            $class_name = $this->class_factory->getObjectName('form');
1358            $this->logger->log(LOG_DEBUG, 'form class is not defined [%s] -> falling back to default [%s]', $action_obj['form_name'], $class_name);
1359            $action_obj['form_name'] = $class_name;
1360        }
1361
1362        $action_obj['inspect'] = true;
1363        $action[$action_name] = $action_obj;
1364        return $action[$action_name];
1365    }
1366
1367    /**
1368     *  ??????????????????????????????????
1369     *
1370     *  @access protected
1371     *  @param  string  $action_name    ??????
1372     *  @param  string  $retval         ??????????????
1373     *  @return string  ???
1374     */
1375    function _sortForward($action_name, $retval)
1376    {
1377        return $retval;
1378    }
1379
1380    /**
1381     *  ?????????????
1382     *
1383     *  @access private
1384     */
1385    function _createFilterChain()
1386    {
1387        $this->filter_chain = array();
1388        foreach ($this->filter as $filter) {
1389            $filter_plugin =& $this->plugin->getPlugin('Filter', $filter);
1390            if (Ethna::isError($filter_plugin)) {
1391                continue;
1392            }
1393
1394            $this->filter_chain[] =& $filter_plugin;
1395        }
1396    }
1397
1398    /**
1399     *  ?????????????????????????
1400     *
1401     *  @access private
1402     *  @param  string  $action_name            ??????????????
1403     *  @param  array   $default_action_name    ?????????????
1404     *  @return bool    true:?? false:???
1405     */
1406    function _isAcceptableActionName($action_name, $default_action_name)
1407    {
1408        foreach (to_array($default_action_name) as $name) {
1409            if ($action_name == $name) {
1410                return true;
1411            } else if ($name{strlen($name)-1} == '*') {
1412                if (strncmp($action_name, substr($name, 0, -1), strlen($name)-1) == 0) {
1413                    return true;
1414                }
1415            }
1416        }
1417        return false;
1418    }
1419
1420    /**
1421     *  ??????????????????????(??????????????)
1422     *
1423     *  @access public
1424     *  @param  string  $action_name    ??????
1425     *  @return string  ??????????????
1426     */
1427    function getActionFormName($action_name)
1428    {
1429        $action_obj =& $this->_getAction($action_name);
1430        if (is_null($action_obj)) {
1431            return null;
1432        }
1433
1434        return $action_obj['form_name'];
1435    }
1436
1437    /**
1438     *  ???????????????????????????????????????
1439     *
1440     *  ???????[??????ID]_Form_[??????]??????????????????
1441     *
1442     *  @access public
1443     *  @param  string  $action_name    ??????
1444     *  @return string  ??????????
1445     */
1446    function getDefaultFormClass($action_name, $gateway = null)
1447    {
1448        $gateway_prefix = $this->_getGatewayPrefix($gateway);
1449
1450        $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
1451        $r = sprintf("%s_%sForm_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
1452        $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1453
1454        return $r;
1455    }
1456
1457    /**
1458     *  getDefaultFormClass()??????????????????????
1459     *
1460     *  getDefaultFormClass()????????????????????????????
1461     *  ???????(??????)
1462     *
1463     *  @access public
1464     *  @param  string  $class_name     ????????
1465     *  @return string  ??????
1466     */
1467    function actionFormToName($class_name)
1468    {
1469        $prefix = sprintf("%s_Form_", $this->getAppId());
1470        if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
1471            // ???????
1472            return null;
1473        }
1474        $target = $match[1];
1475
1476        $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
1477
1478        return $action_name;
1479    }
1480
1481    /**
1482     *  ?????????????????????????????????????
1483     *
1484     *  ???????_getDefaultActionPath()????????(1?????
1485     *  ??????????????????????)?????????
1486     *  ?????????
1487     *
1488     *  @access public
1489     *  @param  string  $action_name    ??????
1490     *  @return string  form class???????????????
1491     */
1492    function getDefaultFormPath($action_name)
1493    {
1494        return $this->getDefaultActionPath($action_name);
1495    }
1496
1497    /**
1498     *  ??????????????????(??????????????)
1499     *
1500     *  @access public
1501     *  @param  string  $action_name    ????????
1502     *  @return string  ??????????
1503     */
1504    function getActionClassName($action_name)
1505    {
1506        $action_obj =& $this->_getAction($action_name);
1507        if ($action_obj == null) {
1508            return null;
1509        }
1510
1511        return $action_obj['class_name'];
1512    }
1513
1514    /**
1515     *  ????????????????????????????????????????
1516     *
1517     *  ???????[??????ID]_Action_[??????]??????????????????
1518     *
1519     *  @access public
1520     *  @param  string  $action_name    ??????
1521     *  @return string  ?????????
1522     */
1523    function getDefaultActionClass($action_name, $gateway = null)
1524    {
1525        $gateway_prefix = $this->_getGatewayPrefix($gateway);
1526
1527        $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
1528        $r = sprintf("%s_%sAction_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
1529        $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1530
1531        return $r;
1532    }
1533
1534    /**
1535     *  getDefaultActionClass()??????????????????????
1536     *
1537     *  getDefaultActionClass()????????????????????????????
1538     *  ???????(??????)
1539     *
1540     *  @access public
1541     *  @param  string  $class_name     ?????????
1542     *  @return string  ??????
1543     */
1544    function actionClassToName($class_name)
1545    {
1546        $prefix = sprintf("%s_Action_", $this->getAppId());
1547        if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
1548            // ???????
1549            return null;
1550        }
1551        $target = $match[1];
1552
1553        $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
1554
1555        return $action_name;
1556    }
1557
1558    /**
1559     *  ??????????????????????????????????????
1560     *
1561     *  ???????"foo_bar" -> "/Foo/Bar.php"???????????????????
1562     *
1563     *  @access public
1564     *  @param  string  $action_name    ??????
1565     *  @return string  ???????????????????????
1566     */
1567    function getDefaultActionPath($action_name)
1568    {
1569        $r = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($action_name)) . '.' . $this->getExt('php');
1570        $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
1571
1572        return $r;
1573    }
1574
1575    /**
1576     *  ???????????????????????(??????????????)
1577     *
1578     *  @access public
1579     *  @param  string  $forward_name   ??????
1580     *  @return string  view class?????
1581     */
1582    function getViewClassName($forward_name)
1583    {
1584        if ($forward_name == null) {
1585            return null;
1586        }
1587
1588        if (isset($this->forward[$forward_name])) {
1589            $forward_obj = $this->forward[$forward_name];
1590        } else {
1591            $forward_obj = array();
1592        }
1593
1594        if (isset($forward_obj['view_name'])) {
1595            $class_name = $forward_obj['view_name'];
1596            if (class_exists($class_name)) {
1597                return $class_name;
1598            }
1599        } else {
1600            $class_name = null;
1601        }
1602
1603        // view???????
1604        $this->_includeViewScript($forward_obj, $forward_name);
1605
1606        if (is_null($class_name) == false && class_exists($class_name)) {
1607            return $class_name;
1608        } else if (is_null($class_name) == false) {
1609            $this->logger->log(LOG_WARNING, 'stated view class is not defined [%s] -> try default', $class_name);
1610        }
1611
1612        $class_name = $this->getDefaultViewClass($forward_name);
1613        if (class_exists($class_name)) {
1614            return $class_name;
1615        } else {
1616            $class_name = $this->class_factory->getObjectName('view');
1617            $this->logger->log(LOG_DEBUG, 'view class is not defined for [%s] -> use default [%s]', $forward_name, $class_name);
1618            return $class_name;
1619        }
1620    }
1621
1622    /**
1623     *  ????????????????????????????????????
1624     *
1625     *  ???????[??????ID]_View_[???]??????????????????
1626     *
1627     *  @access public
1628     *  @param  string  $forward_name   forward?
1629     *  @return string  view class????
1630     */
1631    function getDefaultViewClass($forward_name, $gateway = null)
1632    {
1633        $gateway_prefix = $this->_getGatewayPrefix($gateway);
1634
1635        $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($forward_name));
1636        $r = sprintf("%s_%sView_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
1637        $this->logger->log(LOG_DEBUG, "default view class [%s]", $r);
1638
1639        return $r;
1640    }
1641
1642    /**
1643     *  ??????????????????????????????????
1644     *
1645     *  ???????"foo_bar" -> "/Foo/Bar.php"???????????????????
1646     *
1647     *  @access public
1648     *  @param  string  $forward_name   forward?
1649     *  @return string  view class???????????????
1650     */
1651    function getDefaultViewPath($forward_name)
1652    {
1653        $r = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($forward_name)) . '.' . $this->getExt('php');
1654        $this->logger->log(LOG_DEBUG, "default view path [%s]", $r);
1655
1656        return $r;
1657    }
1658
1659    /**
1660     *  ?????????????????????????????????????
1661     *
1662     *  ???????"foo_bar"???forward??"foo/bar" + ????????????
1663     *  ???????????????
1664     *
1665     *  @access public
1666     *  @param  string  $forward_name   forward?
1667     *  @return string  forward???
1668     */
1669    function getDefaultForwardPath($forward_name)
1670    {
1671        return str_replace('_', '/', $forward_name) . '.' . $this->ext['tpl'];
1672    }
1673
1674    /**
1675     *  ???????????????????
1676     *
1677     *  getDefaultForwardPath()????????????????????????????
1678     *  ???????(??????)
1679     *
1680     *  @access public
1681     *  @param  string  $forward_path   ?????????
1682     *  @return string  ???
1683     */
1684    function forwardPathToName($forward_path)
1685    {
1686        $forward_path = preg_replace('/^\/+/', '', $forward_path);
1687        $forward_path = preg_replace(sprintf('/\.%s$/', $this->getExt('tpl')), '', $forward_path);
1688
1689        return str_replace('/', '_', $forward_path);
1690    }
1691
1692    /**
1693     *  ????????????????????????
1694     *
1695     *  @access private
1696     *  @param  string  $forward_name   forward?
1697     *  @return string  ??????????????
1698     */
1699    function _getForwardPath($forward_name)
1700    {
1701        $forward_obj = null;
1702
1703        if (isset($this->forward[$forward_name]) == false) {
1704            // try default
1705            $this->forward[$forward_name] = array();
1706        }
1707        $forward_obj =& $this->forward[$forward_name];
1708        if (isset($forward_obj['forward_path']) == false) {
1709            // ?????
1710            $forward_obj['forward_path'] = $this->getDefaultForwardPath($forward_name);
1711        }
1712
1713        return $forward_obj['forward_path'];
1714    }
1715
1716    /**
1717     *  ?????????(getTemplateEngine()?????????getRenderer()????????)
1718     *
1719     *  @access public
1720     *  @return object  Ethna_Renderer  ??????????
1721     */
1722    function &getRenderer()
1723    {
1724        $_ret_object =& $this->getTemplateEngine();
1725        return $_ret_object;
1726    }
1727
1728    /**
1729     *  ??????????????
1730     *
1731     *  @access public
1732     *  @return object  Ethna_Renderer  ??????????
1733     *  @obsolete
1734     */
1735    function &getTemplateEngine()
1736    {
1737        if (is_object($this->renderer)) {
1738            return $this->renderer;
1739        }
1740
1741        $this->renderer =& $this->class_factory->getObject('renderer');
1742
1743        //???????????????????
1744        $this->_setDefaultTemplateEngine($this->renderer);
1745        // }}}
1746
1747        return $this->renderer;
1748    }
1749
1750    /**
1751     *  ???????????????????????
1752     *
1753     *  @access protected
1754     *  @param  object  Ethna_Renderer  ??????????
1755     *  @obsolete
1756     */
1757    function _setDefaultTemplateEngine(&$renderer)
1758    {
1759    }
1760
1761    /**
1762     *  ??????????????
1763     *  ??????????????????????????
1764     *  ?????????????????
1765     *
1766     *  @access protected
1767     *  @param  string  $locale             ?????(ja_JP, en_US?)
1768     *                                      (ll_cc ????ll = ????? cc = ????)
1769     *  @param  string  $system_encoding    ?????????????
1770     *  @param  string  $client_encoding    ??????????????(??????????????????????)
1771     *  @see    http://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html
1772     *  @see    Ethna_Controller#_getDefaultLanguage
1773     */
1774    function _setLanguage($locale, $system_encoding = null, $client_encoding = null)
1775    {
1776        $this->locale = $locale;
1777        $this->system_encodin…

Large files files are truncated, but you can click here to view the full file