php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60615 Please extend the classmap option
Submitted: 2011-12-28 11:54 UTC Modified: -
Votes:3
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: juwe at clasennet dot de Assigned:
Status: Open Package: SOAP related
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-12-28 11:54 UTC] juwe at clasennet dot de
Description:
------------
Dear Devs,

currently we can map SOAP requests and responses to userland classes, using the classmap entry from SoapClient::__construct()'s options argument.

Sometimes those userland classes will have dependencies to be injected, before the SoapClient can fill them with their payload. Since SoapClient only accepts class names and not objects to be cloned or at least callbacks to act as a factory, bootstrapping these data objects is impossible.

Could you please change the current behavior in that regard?

In the interest of backwards compatibility, I suggest simply following the callback approach. If a callback is used, instead of a classname, PHP should use that callback as a factory for new classes. 

Test script:
---------------
Example to explain the idea:
<?php


class MySoapClient extends SoapClient
{

  public function __construct($wsdl,$dbAdapter)
  {

    $options = array();
    // hard coded class name
    $options['classmap']['RequestType']  = 'RequestType';

    // anonymous function as factory
    $options['classmap']['ResponseType1'] = function() use($dbAdapter){
                                              $object=new MyResponseMapping();
                                              $object->injectDBAdapter($dbAdapter);
                                              return $object;
                                            };
    // factory method of a given class
    $options['classmap']['ResponseType2'] = array($this,'factoryMethod');

    parent::__construct($wsdl,$options);
  }

  /** a factory method for a certain kind of data access objects 
   *  @param void
   *  @return Object
   */
  public function factoryMethod()
  { 
    $object=new MyResponseMapping();
    $object->injectSourceObject($this);
    return $object;
  }
}

$wsdl         = 'URL 2 a WDSL';

class RequestType

{

    public $payload; 

}


$request         = new RequestType;

$request->payload    = 'payload';



$soapclient = new MySoapClient($wsdl,$dbAdapter);

$result     = $soapclient->doSomething($request);




var_dump($result);


Expected result:
----------------
The var_dump() should reflect that objects of the MyResponseMapping types were used and their dependencies should have been fulfilled using the factories from my example. 

Actual result:
--------------
PHP silently (why?) ignores my mappings and uses stdClass objects instead.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2023-04-04 05:39 UTC] marcusnguyeny75258 at gmail dot com
Thanks for share this information!!!!https://www.mybalancenow.page/php.net
 [2023-04-06 04:12 UTC] jaksujsha32 at gmail dot com
That was so amazing. (https://www.mybalancenow.page/)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC