Development

Changeset 9601

You must first sign up to be able to contribute.

Changeset 9601

Show
Ignore:
Timestamp:
06/16/08 15:55:12 (3 months ago)
Author:
chrisk
Message:

sf1.1 compatible: added support for soap headers; updated documentation;

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/ckWebServicePlugin/trunk/README

    r8904 r9601  
    11= ckWebService plugin = 
    22 
    3 '''This is the documentation for the symfony 1.1 compatible plugin version!''' 
     3'''This is the documentation for the symfony 1.1 compatible plugin version! ''' 
    44 
    55The `ckWebServicePlugin` is a symfony plugin that let you expose your modules and actions as a webservice. 
     
    4949          encoding: utf-8 
    5050          soap_version: %SOAP_1_2% 
     51        # register your SoapHeaders and their corresponding data container class [optional] 
     52        soap_headers: 
     53          FooHeader:                     # name of the soap header 
     54            class: MyFooHeaderDataClass  # name of the data class 
     55          BarHeader: 
     56            class: MyFooHeaderDataClass 
    5157  }}} 
    5258 
    5359=== module.yml === 
    5460 
    55   '''The configuration described here is done by the WSDL Generator!''' 
     61  '''The configuration described here is done by the WSDL Generator! ''' 
    5662   
    5763  The plugin allows per action configuration of parameters passed by the soap call so you can use them like request parameters. 
     
    120126  }}} 
    121127     
    122   It will generate a wsdl file and a controller script in the ''web/'' folder and add / modify all ''module.yml'' files of enabled actions. 
     128  It will generate a wsdl file and a controller script in the ''web/'' folder and add / modify all ''module.yml'' files of your actions. 
    123129 
    124130=== Example === 
     
    174180   
    175181  '''Attention:''' This class has no ''getSoapResult'' method, because the result of the action is stored in the ''result'' member, see 'Internals'->'Getting the action result' for more details. 
     182 
     183== SoapHeader == 
     184 
     185  The plugin also supports the use of SoapHeaders. You can use them to send additional data, like authentication data, with a method call. 
     186   
     187  The data a soap header carries is always stored in a complex type, that means you have to specify a class in which the SoapServer can put the incoming data. For compatibility reasons to Microsofts .NET Framework webservice implementation the SoapHeader and the data class need to have the same name. 
     188  But fortunatly PHP's ''SoapServer'' implementation allows a mapping of types, defined in the *.wsdl file, to PHP classes. To define these mappings you have to use the ''soap_headers'' setting in ''app.yml''. The keys in this array are always the names of the SoapHeaders. The values are arrays containing a key ''class'' and as value the name of the data class. 
     189  This enables you to give SoapHeaders, transporting the same kind of data, different names. 
     190   
     191  The data classes have to be in your application's ''lib/'' folder or a module's ''lib/'' folder. 
     192   
     193  To handle incoming headers you have to listen to the ''webservice.handle_header'' event, it is a ''notifyUntil'' event. 
     194  The event has two parameters. The first is ''header'' containing the name of the SoapHeader. The second is ''data'' containing an instance of the data class. 
     195  If you want to modify the headers value, use ''$event->setReturnValue($modifiedData)'' where ''$modifiedData'' is an instance of the data class. 
     196   
     197  The following example shows how to process a SoapHeader: 
     198   
     199  {{{ 
     200  #php 
     201  <?php 
     202   
     203  /** 
     204   * WrappedString stores a simple string send with a SoapHeader. 
     205   */ 
     206  class WrappedString 
     207  { 
     208    public $data = ""; 
     209  } 
     210     
     211  /** 
     212   * SoapHeaderListener listens to the webservice.handle_header event for the MyFooHeader. 
     213   */ 
     214  class SoapHeaderListener 
     215  { 
     216    const HEADER_NAME = 'MyFooHeader'; 
     217     
     218    /** 
     219     * Constructor connects the SoapHeaderListener with the webservice.handle_header event. 
     220     * 
     221     * @param sfEventDispatcher $dispatcher The sfEventDispatcher instance. 
     222     */ 
     223    public function __construct(sfEventDispatcher $dispatcher) 
     224    { 
     225      $dispatcher->connect('webservice.handle_header', array($this, 'listenToWebserviceHandleHeaderEvent')); 
     226    } 
     227   
     228    /** 
     229     * Handles a webservice.handle_header event, if the header is of type MyFooHeader. 
     230     * 
     231     * @param sfEvent $event A sfEvent instance. 
     232     */ 
     233    public function listenToWebserviceHandleHeaderEvent(sfEvent $event) 
     234    { 
     235      if($event['header'] == self::HEADER_NAME) 
     236      { 
     237        $return = new WrappedString();         
     238        $return->data = sprintf('%s --- has been processed.', $event['data']->data); 
     239         
     240        $event->setReturnValue($return); 
     241       
     242        return true; 
     243      } 
     244      else 
     245      { 
     246        return false; 
     247      } 
     248    } 
     249  } 
     250   
     251  ?> 
     252  }}} 
     253   
     254  '''Attention:''' SoapHeaders are not yet supported by the WSDL Generator task, so you have to define them yourself in the *.wsdl file. 
    176255 
    177256== Internals == 
     
    242321== TODO == 
    243322 
    244   * add support for soap headers 
     323  * add support for soap headers to generator 
    245324  * decide how to handle redirects 
    246325  * write tests 
  • plugins/ckWebServicePlugin/trunk/lib/controller/ckWebServiceController.class.php

    r8905 r9601  
    2323  protected $soap_server = null; 
    2424 
     25  protected $soap_headers = array(); 
     26   
    2527  /** 
    2628   * Initializes this controller. 
     
    3133  { 
    3234    parent::initialize($context); 
     35     
    3336    $this->dispatcher->connect('controller.change_action', array($this, 'listenToControllerChangeActionEvent')); 
    3437  } 
     
    8386    $persist = sfConfig::get('app_ck_web_service_plugin_persist', SOAP_PERSISTENCE_SESSION); 
    8487 
     88    $this->soap_headers = sfConfig::get('app_ck_web_service_plugin_soap_headers', array()); 
     89     
     90    if(!isset($options['classmap']) || !is_array($options['classmap'])) 
     91    { 
     92      $options['classmap'] = array(); 
     93    } 
     94     
     95    foreach($headers as $header_name => $header_options) 
     96    { 
     97      if(isset($header_options['class'])) 
     98      { 
     99        $options['classmap'][$header_name] = $header_options['class']; 
     100      } 
     101    } 
     102     
    85103    if (sfConfig::get('sf_logging_enabled')) 
    86104    { 
     
    114132  public function __call($method, $arguments) 
    115133  { 
    116     $method = explode('_', $method); 
    117  
    118     $moduleName = $method[0]; 
    119     $actionName = isset($method[1]) && strlen($method[1]) > 0 ? $method[1] : 'index'; 
    120  
    121     return $this->invokeSoapEnabledAction($moduleName, $actionName, $arguments); 
     134    if(isset($this->soap_headers[$method])) 
     135    { 
     136      $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'webservice.handle_header', array('header'=>$method, 'data'=>$arguments[0]))); 
     137     
     138      if(!$event->isProcessed() && sfConfig::get('sf_logging_enabled')) 
     139      { 
     140        $this->context->getLogger()->info(sprintf('{%s} SoapHeader \'%s\' unhandled.', __CLASS__, $method)); 
     141      } 
     142       
     143      $result = $event->getReturnValue(); 
     144       
     145      return !is_null($result) ? $result : $arguments[0]; 
     146    } 
     147    else 
     148    { 
     149      $method = explode('_', $method); 
     150 
     151      $moduleName = $method[0]; 
     152      $actionName = isset($method[1]) && strlen($method[1]) > 0 ? $method[1] : 'index'; 
     153 
     154      return $this->invokeSoapEnabledAction($moduleName, $actionName, $arguments); 
     155    } 
    122156  } 
    123157 
  • plugins/ckWebServicePlugin/trunk/package.xml

    r8895 r9601  
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2008-05-04</date> 
     13 <date>2008-06-16</date> 
    1414 <version> 
    15   <release>1.3.0</release> 
    16   <api>1.3.0</api> 
     15  <release>2.0.0</release> 
     16  <api>2.0.0</api> 
    1717 </version> 
    1818 <stability>