Re: Converting xmlrpcval object array to PHP object array abstractly or dynamically?

Gaetano Giunta <[email protected]> Sun, 16 Jun 2013 22:49:01 +0200
Newsgroups gmane.comp.php.xml-rpc
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============5329508386013211502==
Content-Type: multipart/alternative;
 boundary="------------000702010006070802040902"

This is a multi-part message in MIME format.
--------------000702010006070802040902
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Nice to see someone still using phpxmlrpc. Old tech never dies! :-)

On a more serious note:

- the phpxmlrpc lib has functions which do recursive encoding/decoding. they are even in the manual ;-)

- the simplest way to be able to serve calls with unknown number of parameters is to actually only use 1 parameter, of type "array". In the array then the 
elements will be the real parameters for the actual call on the php side. Of course you loose the param/type validation done for you by the lib, and might have 
to rewrite some on your own

- if you feel adventurous, with some introspection magic you could even use a struct as top-level param and allow named-parameters over xmlrpc become 
positional-parameters for the php calls. iirc there is some sample code in the lib doing that - used by the debugger

- the main limitation to this scheme is that you are bound not to pass around php objects but only php arrays/hashes. This is generally a good idea, security-wise

- if you use php_xmlrpc on both sides of the tunnel, there even is an option for the phpxmlrpc_encode and _decode calls which allows embedding in the produced 
xml some slightly-out-of-band information.
This allows the lib to tell apart php hashes from php objects. You will then be able to basically map ANY php function to its remote counterpart - except for 
the parameters which reference resources (eg a db connection can not be serialized across the net) or the objects with circular references (take care!)

Do not hesitate to come back if there's anything I said which is not crystal clear

bye
Gaetano

David Luu wrote:
> Hello,
>
> Don't know if anyone has asked this before, since the mailing list archive spans a long time, it's just easier for me to re-ask if asked before.
>
> I'm working on a XML-RPC service that reflects any given PHP class. One XML-RPC method takes any number of arguments from the XML-RPC request/call.
>
> In the XML-RPC method, I then store all the arguments into a PHP array of xmlrpcvals, via iterating over xmlrpcmsg->getParam(n) for the total # of params 
> based on getNumParams().
>
> I would then like to dynamically/abstractly handle converting each element of that xmlrpcval array into its PHP object equivalent, where the element may be a 
> scalar, array, or struct (generally scalar or array). And that array may contain yet more scalars, arrays, or structs (though for simple case most likely 
> scalars).
>
> How might I recursively and/or iteratively parse the xmlrpcval array into it's PHP equivalent in a way that handles all cases? Since we don't know until 
> runtime (i.e. when XML-RPC call is made) what the exact arguments are (type and number of them).
>
> Has anyone done something similar before? I've done similar for other language platforms but those libraries did more implicit conversion handling for me, so 
> I didn't have to go into this level of detail as with this PHP library.
>
> I'm planning to try to work something out when I have time, and in the meantime, handle the simple case for now where the array will always be of scalars (not 
> array within array), and ignore structs. And wanted to see what feedback/tips I can get from the community, hence this email.
>
> Regards,
> David
>
>
> _______________________________________________
> phpxmlrpc mailing list
> [email protected]
> http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc


--------------000702010006070802040902
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Nice to see someone still using
      phpxmlrpc. Old tech never dies! :-)<br>
      <br>
      On a more serious note:<br>
      <br>
      - the phpxmlrpc lib has functions which do recursive
      encoding/decoding. they are even in the manual ;-)<br>
      <br>
      - the simplest way to be able to serve calls with unknown number
      of parameters is to actually only use 1 parameter, of type
      "array". In the array then the elements will be the real
      parameters for the actual call on the php side. Of course you
      loose the param/type validation done for you by the lib, and might
      have to rewrite some on your own<br>
      <br>
      - if you feel adventurous, with some introspection magic you could
      even use a struct as top-level param and allow named-parameters
      over xmlrpc become positional-parameters for the php calls. iirc
      there is some sample code in the lib doing that - used by the
      debugger<br>
      <br>
      - the main limitation to this scheme is that you are bound not to
      pass around php objects but only php arrays/hashes. This is
      generally a good idea, security-wise<br>
      <br>
      - if you use php_xmlrpc on both sides of the tunnel, there even is
      an option for the phpxmlrpc_encode and _decode calls which allows
      embedding in the produced xml some slightly-out-of-band
      information.<br>
      This allows the lib to tell apart php hashes from php objects. You
      will then be able to basically map ANY php function to its remote
      counterpart - except for the parameters which reference resources
      (eg a db connection can not be serialized across the net) or the
      objects with circular references (take care!)<br>
      <br>
      Do not hesitate to come back if there's anything I said which is
      not crystal clear<br>
      <br>
      bye<br>
      Gaetano<br>
      <br>
      David Luu wrote:<br>
    </div>
    <blockquote
cite="mid:CA+V6+ZChYe41AQ8pwNetKVjV7JmYX6LiN-r+NLLtJHMH+5ZEug@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Hello,<br>
        </div>
        <div><br>
        </div>
        <div>Don't know if anyone has asked this before, since the
          mailing list archive spans a long time, it's just easier for
          me to re-ask if asked before.</div>
        <div><br>
        </div>
        <div>I'm working on a XML-RPC service that reflects any given
          PHP class. One XML-RPC method takes any number of arguments
          from the XML-RPC request/call.</div>
        <div><br>
        </div>
        <div>In the XML-RPC method, I then store all the arguments into
          a PHP array of xmlrpcvals, via iterating over
          xmlrpcmsg-&gt;getParam(n) for the total # of params based on
          getNumParams().</div>
        <div><br>
        </div>
        <div>I would then like to dynamically/abstractly handle
          converting each element of that xmlrpcval array into its PHP
          object equivalent, where the element may be a scalar, array,
          or struct (generally scalar or array). And that array may
          contain yet more scalars, arrays, or structs (though for
          simple case most likely scalars).</div>
        <div><br>
        </div>
        <div>How might I recursively and/or iteratively parse the
          xmlrpcval array into it's PHP equivalent in a way that handles
          all cases? Since we don't know until runtime (i.e. when
          XML-RPC call is made) what the exact arguments are (type and
          number of them).</div>
        <div><br>
        </div>
        <div>Has anyone done something similar before? I've done similar
          for other language platforms but those libraries did more
          implicit conversion handling for me, so I didn't have to go
          into this level of detail as with this PHP library.</div>
        <div><br>
        </div>
        <div>I'm planning to try to work something out when I have time,
          and in the meantime, handle the simple case for now where the
          array will always be of scalars (not array within array), and
          ignore structs. And wanted to see what feedback/tips I can get
          from the community, hence this email.</div>
        <div><br>
        </div>
        <div>Regards,</div>
        <div>David</div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
phpxmlrpc mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc">http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>

--------------000702010006070802040902--

--===============5329508386013211502==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
phpxmlrpc mailing list
[email protected]
http://lists.usefulinc.com/cgi-bin/mailman/listinfo/phpxmlrpc

--===============5329508386013211502==--