Changeset 9601
- Timestamp:
- 06/16/08 15:55:12 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/ckWebServicePlugin/trunk/README
r8904 r9601 1 1 = ckWebService plugin = 2 2 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! ''' 4 4 5 5 The `ckWebServicePlugin` is a symfony plugin that let you expose your modules and actions as a webservice. … … 49 49 encoding: utf-8 50 50 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 51 57 }}} 52 58 53 59 === module.yml === 54 60 55 '''The configuration described here is done by the WSDL Generator! '''61 '''The configuration described here is done by the WSDL Generator! ''' 56 62 57 63 The plugin allows per action configuration of parameters passed by the soap call so you can use them like request parameters. … … 120 126 }}} 121 127 122 It will generate a wsdl file and a controller script in the ''web/'' folder and add / modify all ''module.yml'' files of enabledactions.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. 123 129 124 130 === Example === … … 174 180 175 181 '''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. 176 255 177 256 == Internals == … … 242 321 == TODO == 243 322 244 * add support for soap headers 323 * add support for soap headers to generator 245 324 * decide how to handle redirects 246 325 * write tests plugins/ckWebServicePlugin/trunk/lib/controller/ckWebServiceController.class.php
r8905 r9601 23 23 protected $soap_server = null; 24 24 25 protected $soap_headers = array(); 26 25 27 /** 26 28 * Initializes this controller. … … 31 33 { 32 34 parent::initialize($context); 35 33 36 $this->dispatcher->connect('controller.change_action', array($this, 'listenToControllerChangeActionEvent')); 34 37 } … … 83 86 $persist = sfConfig::get('app_ck_web_service_plugin_persist', SOAP_PERSISTENCE_SESSION); 84 87 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 85 103 if (sfConfig::get('sf_logging_enabled')) 86 104 { … … 114 132 public function __call($method, $arguments) 115 133 { 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 } 122 156 } 123 157 plugins/ckWebServicePlugin/trunk/package.xml
r8895 r9601 11 11 <active>yes</active> 12 12 </lead> 13 <date>2008-0 5-04</date>13 <date>2008-06-16</date> 14 14 <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> 17 17 </version> 18 18 <stability>