Source for file GatewayGenerator.php

Documentation is available at GatewayGenerator.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  GatewayGenerator.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: cf6f9429533a074f4f65fabc5d60d9a7b8353ef4 $
  10.  */
  11.  
  12. // {{{ Ethna_SOAP_GatewayGenerator
  13. /**
  14.  *  指定されたコントローラに対応するゲートウェイクラスコードを生成するクラス
  15.  *
  16.  *  @author     Masaki Fujimoto <fujimoto@php.net>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /**#@+
  22.      *  @access private
  23.      */
  24.  
  25.     /** @var    object  Ethna_Controller    controllerオブジェクト */
  26.     var $controller;
  27.  
  28.     /** @var    object  Ethna_Config        設定オブジェクト */
  29.     var $config;
  30.  
  31.     /** @var    object  Ethna_ActionError   アクションエラーオブジェクト */
  32.     var $action_error;
  33.  
  34.     /** @var    object  Ethna_ActionError   アクションエラーオブジェクト(省略形) */
  35.     var $ae;
  36.  
  37.     /** @var    string      ゲートウェイクラスコード */
  38.     var $gateway;
  39.  
  40.     /** @var    string      ゲートウェイクラス識別名 */
  41.     var $name;
  42.  
  43.     /** @var    string      ゲートウェイクラスネームスペース */
  44.     var $namespace;
  45.  
  46.     /**#@-*/
  47.  
  48.     /**
  49.      *  Ethna_SOAP_GatewayGeneratorクラスのコンストラクタ
  50.      *
  51.      *  @access public
  52.      */
  53.     public function __construct()
  54.     {
  55.         $this->controller Ethna_Controller::getInstance();
  56.         $this->config $this->controller->getConfig();
  57.         $this->action_error null;
  58.         $this->ae $this->action_error;
  59.         $this->gateway "";
  60.         $this->name $this->controller->getAppId();
  61.         $this->namespace $this->_getNameSpace();
  62.     }
  63.  
  64.     /**
  65.      *  ゲートウェイクラスコードを生成する
  66.      *
  67.      *  @access public
  68.      *  @return string  ゲートウェクラスコード
  69.      */
  70.     function generate()
  71.     {
  72.         $prev_type $this->controller->getClientType();
  73.         $this->controller->setClientType(CLIENT_TYPE_SOAP);
  74.  
  75.         $this->gateway .= $this->_getHeader();
  76.         $this->gateway .= $this->_getEntry();
  77.         $this->gateway .= $this->_getFooter();
  78.  
  79.         $this->controller->setClientType($prev_type);
  80.  
  81.         return $this->gateway;
  82.     }
  83.  
  84.     /**
  85.      *  ゲートウェイクラスのクラス名を取得する
  86.      *
  87.      *  @access public
  88.      *  @return string  ゲートウェイクラスのクラス名
  89.      */
  90.     function getClassName()
  91.     {
  92.         return sprintf("Ethna_SOAP_%sGateway"$this->name);
  93.     }
  94.  
  95.     /**
  96.      *  ゲートウェイクラスコード(ヘッダ部分)を取得する
  97.      *
  98.      *  @access private
  99.      *  @return string  ゲートウェイクラスコード(ヘッダ部分)
  100.      */
  101.     function _getHeader()
  102.     {
  103.         $header sprintf("class Ethna_SOAP_%sGateway extends Ethna_SOAP_Gateway {\n"$this->name);
  104.  
  105.         return $header;
  106.     }
  107.  
  108.     /**
  109.      *  ゲートウェイクラスコード(メソッドエントリ部分)を取得する
  110.      *
  111.      *  @access private
  112.      *  @return string  ゲートウェイクラスコード(メソッドエントリ部分)
  113.      */
  114.     function _getEntry()
  115.     {
  116.         $entry "";
  117.         foreach ($this->controller->soap_action as $k => $v{
  118.             $action_form_name $this->controller->getActionFormName($k);
  119.             $form new $action_form_name($this->controller);
  120.             $arg_list array_keys($form->form);
  121.  
  122.             $entry .= "  function $k(";
  123.             for ($i 0$i count($arg_list)$i++{
  124.                 if ($i 0{
  125.                     $entry .= ", ";
  126.                 }
  127.                 $entry .= "\$" $arg_list[$i];
  128.             }
  129.             $entry .= ") {\n";
  130.  
  131.             $entry .= "    \$_SERVER['REQUEST_METHOD'] = 'post';\n";
  132.             $entry .= "    \$_POST['action_$k'] = 'dummy';\n";
  133.             foreach ($arg_list as $arg{
  134.                 $entry .= "    \$_POST['$arg'] = \$$arg;\n";
  135.             }
  136.             
  137.             $entry .= "    \$this->dispatch();\n";
  138.  
  139.             $entry .= "    \$app = \$this->getApp();\n";
  140.             $entry .= "    \$errorcode = \$this->getErrorCode();\n";
  141.             $entry .= "    \$errormessage = \$this->getErrorMessage();\n";
  142.             $entry .= "    \$retval = array();\n";
  143.             foreach ($form->retval as $k => $v{
  144.                 $entry .= "    \$retval['$k'] = \$app['$k'];\n";
  145.             }
  146.             $entry .= "    \$retval['errorcode'] = \$errorcode;\n";
  147.             $entry .= "    \$retval['errormessage'] = \$errormessage;\n";
  148.  
  149.             $entry .= "    return \$retval;\n";
  150.             $entry .= "  }\n";
  151.         }
  152.         return $entry;
  153.     }
  154.  
  155.     /**
  156.      *  ゲートウェイクラスコード(フッタ部分)を取得する
  157.      *
  158.      *  @access private
  159.      *  @return string  ゲートウェイクラスコード(フッタ部分)
  160.      */
  161.     function _getFooter()
  162.     {
  163.         $footer "}\n";
  164.  
  165.         return $footer;
  166.     }
  167.  
  168.     /**
  169.      *  ネームスペースを取得する
  170.      *
  171.      *  @access private
  172.      *  @return string  ネームスペース
  173.      */
  174.     function _getNameSpace()
  175.     {
  176.         return sprintf("%s/%s"$this->config->get('url')$this->name);
  177.     }
  178. }
  179. // }}}

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