On 4 May, 19:10, Michael Caplan <[EMAIL PROTECTED]>
wrote:
> Hi there,
>
> Maybe this is off topic, and I apologize if it is.  I'm trying to get
> my head around how to represent complex return types for a SCA
> service.  The result type is to be a associative array.  I think I am
> on the right track with trying to define an XML Schema doc that
> defines the structure, and then reference it with a @types
> annotation.  Bit, I'm having problems figuring out how to represent an
> associative array as XML Schema.  Any tips?
>
> Thanks,
>
> Mike
Hi Mike

At the moment we are using the SDO technology included in the SCA_SDO
package to represent complex types as they pass in and out of SCA
services. So, for example, to define a complex type that a  service
might return you might do something like (this is code from the SCA/
emailcontact example cut down a bit)...

/**
 * @service
 * @binding.jsonrpc
 * @types http://example.org/contacts contacts.xsd
 */
class ContactService {

    /**
     * Retrieve contact details
     *
     * @param string $shortname The short name of the contact
     * @return contact http://example.org/contacts The full contact
details
     */
    public function retrieve($shortname) {
            $contact = SCA::createDataObject('http://example.org/
contacts', 'contact');
            $contact->shortname = "fred";
            $contact->fullname = "Fred Bloggs";
            $contact->email = "[EMAIL PROTECTED]";
            return $contact;
    }

The points of interest here are that:

* @types  defines the schema that will be used
* @return   defines the type from the scehma that will be returned
SCA::createDataObject('http://example.org/contacts', 'contact');
creates an SDO of the type requested
  $contact->shortname etc. just fills in the data object elements as
defined in the schema

The schema by the way is:

<schema xmlns=...>
  <element name="contact">
    <complexType>
      <sequence>
        <element name="shortname" type="string" />
        <element name="fullname" type="string" nillable="true" />
        <element name="email" type="string" nillable="true" />
      </sequence>
    </complexType>
  </element>
</schema>

Now to associative arrays. SDO itself acts a little like an
associative array in that you can set properties of the SDO as though
they are associative array elements. I.e you should be able to set

$contact["fullname"] = "Fred Bloggs";

However you are still bounded by the property names defined in the
schema. If this doesn't provide enough flexibility SDO will handle
"open" types in XML schema, for example, If we extend the schema above
to

<schema xmlns=...>
  <element name="contact">
    <complexType>
      <sequence>
        <element name="shortname" type="string" />
        <element name="fullname" type="string" nillable="true" />
        <element name="email" type="string" nillable="true" />
        <any namespace="##any" maxOccurs="unbounded"/>
      </sequence>
    </complexType>
  </element>
</schema>

Then SDO will allow us to adde new elements on the fly.


$contact["xyz"] = "Fred Bloggs";

We don't support creating SDOs statically using the normal PHP array
syntax but there is a resonable amount of flexibility in the SDO
interface. If you wanted to play with SDO outside of SCA here is a
little test script that demonstrates the above....

    $xmldas = SDO_DAS_XML::create();
    $xmldas->addTypes("contacts.xsd");
    $doc = $xmldas->createDocument();
    $contact = $doc->getRootDataObject();
    $contact["shortname"] = "fred";
    $contact->fullname = "Fred Bloggs";
    $contact->email = "[EMAIL PROTECTED]";
    $contact["xyz"] = "Fred Bloggs";
    print_r($contact);

Regards

Simon


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"phpsoa" group.
To post to this group, send email to phpsoa@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.co.uk/group/phpsoa?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to