<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; wsdl2php</title>
	<atom:link href="http://www.dimuthu.org/tag/wsdl2php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 07 Jul 2010 12:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>XML Schema Simple Types &amp; How WSDL2PHP Convert Them To PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 15:28:50 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[built-in]]></category>
		<category><![CDATA[facets]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[primitive]]></category>
		<category><![CDATA[simple types]]></category>
		<category><![CDATA[union]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=598</guid>
		<description><![CDATA[As many of other languages, XML schema too have data types. Basically it can be categorized in to two groups. Simple Types Complex Types The different between these 2 types are so easy to identify. Say you have a schema element with a simple type like this. &#60;xs:element name="xx" type="someSimpleType"/&#62; Then a possible xml to [...]]]></description>
			<content:encoded><![CDATA[<p>As many of other languages, XML schema too have data types. Basically it can be categorized in to two groups.</p>
<ol>
<li>Simple Types</li>
<li>Complex Types</li>
</ol>
<p>The different between these 2 types are so easy to identify. Say you have a schema element with a simple type like this.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"xx"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"someSimpleType"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>Then a possible xml to validate against this schema is</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xx<span style="font-weight: bold; color: black;">&gt;</span></span></span>Bingo<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/x<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Inside the &#8216;xxx&#8217; you can only find texts, But in a case of a  schema element with complex types,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"xx"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"someComplexType"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>The XML will be set of nested elements.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xx<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;yy<span style="font-weight: bold; color: black;">&gt;</span></span></span>hi<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/yy<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;zz<span style="font-weight: bold; color: black;">&gt;</span></span></span>Nested elements<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/zz<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xx<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Simply complex type contains elements with simple types or complex types similar to the class types in OOP languages which contain member variables with different types.</p>
<p>But unlike most of the other languages, in schema simple types are not always primitive types. There can be user derived simple types as well.</p>
<p>I will talk about each of these variations in schema types and their PHP representation of <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">WSDL2PHP tool</a>.</p>
<ul>
<li>Primitive Types &amp; Built-in Types</li>
<li>List Types</li>
<li>Union Types</li>
<li>Faceted Types</li>
</ul>
<p><strong>Primitive Types &amp; Built-in Types<br />
</strong></p>
<p>The XML schema specification talks about <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">19 primitive types</a>. Some of the common of these simple types and the corresponding PHP types generated by WSDL2PHP tool are,</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Schema Type</td>
<td>PHP Type</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#string">string</a></td>
<td>string</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#boolean">boolean</a></td>
<td>boolean</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#decimal">decimal</a></td>
<td>float</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#float">float</a></td>
<td>float</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#double">double</a></td>
<td>double</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#duration">duration</a></td>
<td>string</td>
</tr>
<tr>
<td><a href="http://www.w3.org/TR/xmlschema-2/#dateTime">dateTime</a></td>
<td>string (from above wsf/php 2.0 it is an integer &#8211; representing timestamp)</td>
</tr>
</tbody>
</table>
<p>You may have noticed the famous types like &#8216;integer&#8217;, &#8216;byte&#8217;, &#8216;short&#8217; are missing out of the above list. In fact these types exist, but they are not primitive types. They are derived from decimal (special cases when the fraction digits are 0 <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Anyway still these types are considered built-in types in xml schema. Here is the <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">complete list of built-in types</a> (both primitive and non-primitive built-in types)</p>
<p>&#8216;integer&#8217;, &#8216;byte&#8217; and &#8216;short&#8217; are mapped to PHP integer types by the WSDL2PHP tool.</p>
<p>To show an example how WSDL2PHP tool generating code for simple types, I will take the following schema Element.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myName"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And WSDL2PHP will generate a simple public variable (Assuming this is generating inside some class) for that element with a comment to describing it.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
     <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$myName</span>;</pre>
<p>So if I specified some value for the variable (Taking the variable name of the parent class is $parent),</p>
<pre class="php"><span style="color: #0000ff;">$parent</span>-&gt;<span style="color: #006600;">myName</span> = <span style="color: #ff0000;">"James"</span>;</pre>
<p>I will get the following nice XML.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;myName<span style="font-weight: bold; color: black;">&gt;</span></span></span>James<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/myName<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>This is the same approach for all the other built-in types as well.</p>
<p><strong>List Types</strong></p>
<p>The list types are derived from list of simple types. It still a simple type because it list all the element in the list as a white-space separated text inside the parent element.</p>
<p>Here is how you may declare a list type in an xml schema.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"mylist"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:list</span> <span style="color: #000066;">itemType</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above list value --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"xCoordinates"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:mylist"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>Then the WSDL2PHP generated PHP code would be something like,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var array of int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$xCoordinates</span>;</pre>
<p>As the comment implies, you have to feed the values in an php array.</p>
<pre class="xml"><span style="color: #0000ff;">$parent</span>-&gt;<span style="color: #006600;">xCoordinates</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">8</span>, <span style="color: #cc66cc;">7</span>, <span style="color: #cc66cc;">9</span><span style="color: #66cc66;">)</span>;</pre>
<p>And Here is the XML you are getting,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xCoordinates<span style="font-weight: bold; color: black;">&gt;</span></span></span>1 3 8 7 9<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xCoordinates<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Similarly you can have list of any simple types regardless whether it is built-in or derived.</p>
<p><strong>Union Types</strong></p>
<p>The union in schema is similar to the unions in &#8216;C&#8217;. In C variables of a union can have one (and not more than one) of the types declared inside the union type. Similarly in schema elements with union types can have one and only one simple type among the member types declared in the union. Here is an example of declaring union type,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myIntStringUnion"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:union</span> <span style="color: #000066;">memberTypes</span>=<span style="color: #ff0000;">"xs:int xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above union value --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"garbage"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:myIntStringUnion"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And the WSDl2PHP generated code,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var int/string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$garbage</span>;</pre>
<p>So if you read the comment you can have an idea that this variable accept either &#8216;in&#8217; or &#8216;string&#8217; type without digging in to the WSDL.</p>
<p><strong>Faceted Types</strong></p>
<p>You can apply facets and restrict the value space of a simple type.</p>
<ul>
<li>length</li>
<li>minLength</li>
<li>maxLength</li>
<li>pattern</li>
<li>enumeration</li>
<li>whiteSpace</li>
<li>maxInclusive</li>
<li>maxExclusive</li>
<li>minExclusive</li>
<li>minInclusive</li>
<li>totalDigits</li>
<li>fractionDigits</li>
</ul>
<p>Some facets are specific to some built-in data types or types derived from these built-in datatypes. <a href="http://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes">Here is a table of valid facets</a> for each of the above mentioned catagory of types.</p>
<p>I have earlier blogged about how you work on faceted types in PHP in the post &#8220;<a href="http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/">Coding Schema Inheritance in PHP</a>&#8220;. So Here I will list out a similar example  to demonstrate the PHP generated code by WSDL2PHP tool for facets.</p>
<p>Here is a schema with the &#8216;enumeration&#8217; facet.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- applying enumeration facet to the xs:string --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"mySubject"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:restriction</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"Maths"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"Physics"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
         <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"Chemistry"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:restriction<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

<span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- example element to have the above faceted value --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"subject"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:mySubject"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And here is the WSDL2PHP generated code,</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: subject should follow the following restrictions
     *     You can have one of the following value
     *     Maths
     *     Physics
     *     Chemistry
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$subject</span>;</pre>
<p>It clearly says your variable &#8216;subject&#8217; is only allowed to have the list of values mentioned in the &#8216;enumeration&#8217;.</p>
<p>So I just wrote about some variations of simple schema types and how they are represented in the WSDL2PHP generated code. As you may have observed, you don&#8217;t need to know any thing about the WSDL or the schema to write a PHP code around that, since WSDL2PHP gives you a generated code mentioning all the guidelines, restrictions about using them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/13/xml-schema-simple-types-how-wsdl2php-convert-them-to-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WSF/PHP WSDL Mode &#8211; Handling XML Schema Arrays</title>
		<link>http://www.dimuthu.org/blog/2008/10/25/wsfphp-wsdl-mode-handling-xml-schema-arrays/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/25/wsfphp-wsdl-mode-handling-xml-schema-arrays/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 15:20:40 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[maxOccurs]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wsdl mode]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=543</guid>
		<description><![CDATA[In XML Schema we declare an array or a multiple occurrence of a schema element by setting its maxOccurs attribute to a value greater than 1 or to the value &#8220;unbounded&#8221; in a case of no maximum boundary. &#60;xs:element maxOccurs="unbounded"  minOccurs="0"  name="params"  nillable="true"  type="xs:int"/&#62; If you generate PHP code to such a schema using wsdl2php [...]]]></description>
			<content:encoded><![CDATA[<p>In XML Schema we declare an array or a multiple occurrence of a schema element by setting its maxOccurs attribute to a value greater than 1 or to the value &#8220;unbounded&#8221; in a case of no maximum boundary.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">"unbounded"
           </span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span>
            <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"params"</span>
            <span style="color: #000066;">nillable</span>=<span style="color: #ff0000;">"true"</span>
            <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>If you generate PHP code to such a schema using <a title="online wsdl2php tool" href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdl2php tool</a>, you will get a code for the class variable named &#8220;params&#8221; similar to this.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var array[0, unbounded] of int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$params</span>;</pre>
<p>So if you have a variable (say $object) for the object of this class you can fill the &#8220;params&#8221; field like this,</p>
<pre class="php"><span style="color: #0000ff;">$object</span>-&gt;<span style="color: #006600;">params</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">)</span>;</pre>
<p>This will create the xml with the expected array of elements.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>5<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>8<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Not only for simple types, you can have arrays of complex types too.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">"unbounded"</span>
            <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">"0"</span>
            <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"params"</span>
            <span style="color: #000066;">nillable</span>=<span style="color: #ff0000;">"true"</span>
            <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"tns:MyComplexType"</span><span style="font-weight: bold; color: black;">/&gt;
</span></span></pre>
<p>Instead of giving simple integers like earlier case, this time you will feed the &#8220;params&#8221; variable with an array of PHP objects of &#8216;MyComplexType&#8217; class.</p>
<pre class="php"><span style="color: #0000ff;">$obj1</span> = <span style="font-weight: bold; color: #000000;">new</span> MyComplexType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">/* feeding data to obj1 variables */</span>

<span style="color: #0000ff;">$obj2</span> = <span style="font-weight: bold; color: #000000;">new</span> MyComplexType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">/* feeding data to obj2 variables */</span>

<span style="color: #0000ff;">$obj3</span> = <span style="font-weight: bold; color: #000000;">new</span> MyComplexType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="font-style: italic; color: #808080;">/* feeding data to obj3 variables */</span>

<span style="color: #0000ff;">$object</span>-&gt;<span style="color: #006600;">params</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$obj1</span>, <span style="color: #0000ff;">$obj2</span>, <span style="color: #0000ff;">$obj3</span><span style="color: #66cc66;">)</span>;</pre>
<p>This will create a xml containing array of params similar to this,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;elementx</span><span style="font-weight: bold; color: black;">/&gt;</span></span> <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- elements in the MyComplexType type --&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;elementy</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        ... <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- elements in the MyComplexType type --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        ... <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- elements in the MyComplexType type --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/params<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/wrapper<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/25/wsfphp-wsdl-mode-handling-xml-schema-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding Schema Inheritance in PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 13:07:08 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[complexContent]]></category>
		<category><![CDATA[complexType]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[restriction]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[simpleContent]]></category>
		<category><![CDATA[simpleType]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=517</guid>
		<description><![CDATA[If you are thinking of writing a web service or a client based on a WSDL, you can easily generate the code for PHP or any other language using tools likes wsdl2php or other wsdl2xxx category tools. Then you don&#8217;t need to really worry about what is the schema of the WSDL or any other [...]]]></description>
			<content:encoded><![CDATA[<p>If you are thinking of writing a web service or a client based on a WSDL, you can easily generate the code for PHP or any other language using tools likes wsdl2php or other wsdl2xxx category tools. Then you don&#8217;t need to really worry about what is the schema of the WSDL or any other finer details. But sometime it may useful to know how different schema constructs are generated in PHP level so you can have a good idea when you are using them. This post describes How inheritance is used in XML Schema and how it is mapped to PHP code from <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">wsdl2php tool</a> in <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>.</p>
<p>There are several ways that one schema type can inherit another type.  Here are some names use to refer them.</p>
<ul>
<li>SimpleType Restriction &#8211; Forming simple type by restricting another simple type</li>
<li>SimpleContent Extension &#8211; Forming complex type by extending a simple type</li>
<li>ComplexContent Extension &#8211; Forming complex type by extending another complex type</li>
</ul>
<p>Note that here the word &#8216;type&#8217; always refers to a schema type.</p>
<p>It is not straight forward to do a one to one map from these schema structures to a PHP or some other language. But wsdl2php tool does that keeping the simplicity and preserving the original meaning. Lets see how it is done for each of the above mentioned methods of inheriting.</p>
<p><strong>SimpleType Restriction</strong></p>
<p>You can create a simple type by restricting some values of another simple type. Here is an example.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- derivedType from applying
              simple type restriction for xs:string --&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"derivedType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:restriction</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"a"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"ab"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"abc"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:enumeration</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"abcd"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:restriction<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here the derivedType is a string, but it can only have values &#8220;a&#8221;, &#8220;ab&#8221;, &#8220;abc&#8221; and &#8220;abcd&#8221;. This restriction have used the &#8220;enumeration&#8221; (which we call a facet) to restrict the possible values. You can use other facets like length, minLength, MaxLength and so on. Here are the <a href="http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#rf-facets">complete list of facets in the schema specification</a>.</p>
<p>So lets see hows this is mapped to a PHP code. Here we assume this type is used in an schema element called &#8216;input&#8217;.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: $input should follow the following restrictions
     *     You can have one of the following value
     *     a
     *     ab
     *     abc
     *     abcd
     */</span>
     <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$input</span>;</pre>
<p>Note that here it does not say anything about the &#8216;derivedType&#8217;. Rather it says it is of type &#8220;String&#8221; which is a PHP type and in addition it has some restrictions, or rules when assigning values.</p>
<p>Although it could have been possible to use getters and setters to impose these rules, this uses just a comment about the rules because this way it is really easy the use the variable.</p>
<p>Say we have another type (say derievedType2) restricting the &#8216;derievedType&#8217;, that type will have the combination of restrictions of both types.</p>
<p>Here is the xml schema representation of the &#8216;derievedType2&#8242;.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- derivedType2--&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"derivedType2"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:restriction</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"tns:derivedType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:maxLength</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"3"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:minLength</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"2"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:restriction<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And if input2 have that type, the php code will look like this, (Note that it has the combination of rules).</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var string
     *     NOTE: $input2 should follow the following restrictions
     *     You can have one of the following value
     *     a
     *     ab
     *     abc
     *     abcd
<strong>     *     Your length of the value should be
     *     Greater than 2
     *     Less than 3</strong>
     */</span>
     <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$input2</span>;</pre>
<p>I have highlighted the additional rules compared with $input, so you can see the difference.</p>
<p><strong>SimpleContent Extension</strong></p>
<p>Simple Content extension is extending a simple type to make a complex type. Say we have an element (say with the name &#8220;mystring&#8221;) and it has &#8220;xs:string&#8221; simple type.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"mystring"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></pre>
<p>And here is a valid xml with this schema.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mystring<span style="font-weight: bold; color: black;">&gt;</span></span></span>this can contain only string<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mystring<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So if I say I&#8217;m going to make a complex type extending this simple type you may think that I&#8217;m going to add element in to that. In fact I will create a complex type by adding an attribute.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mystring</span> <span style="color: #000066;">myint</span>=<span style="color: #ff0000;">"3"</span><span style="font-weight: bold; color: black;">&gt;</span></span>this can contain only string<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mystring<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>The schema to this xml will be something like this. (Note that I have assumed there is an schema element named &#8220;mystring&#8221; with the type &#8220;myStringType&#8221;)</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myStringType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:simpleContent<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:extension</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myint"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:extension<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:simpleContent<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>The PHP generated code for this schema is something like this,</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> myStringType <span style="color: #66cc66;">{</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$myint</span>;

    <span style="font-style: italic; color: #808080;">// The "value" represents the element 'myStringType' value..</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$value</span>;

<span style="color: #66cc66;">}</span></pre>
<p>So as you can see it creates a PHP class for that schema type with member variables for each attributes and finally for the value of the parent type. So in order to represent the above mentioned xml, you will use the following PHP code.</p>
<pre class="php"><span style="color: #0000ff;">$type</span> = <span style="font-weight: bold; color: #000000;">new</span> myStringType<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$type</span>-&gt;<span style="color: #006600;">myint</span> = <span style="color: #cc66cc;">3</span>;
<span style="color: #0000ff;">$type</span>-&gt;<span style="color: #006600;">value</span> = <span style="color: #ff0000;">"this can contain only string"</span>;</pre>
<p>Next we will look at the inheritance with complexContent Extension.</p>
<p><strong>ComplexContent Extension</strong></p>
<p>This is to create a complex type by inheriting another complexType.</p>
<pre class="xml">            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- the parent type --&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"parentType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo3"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo4"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>

            <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- the child type --&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"childType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:complexContent<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:extension</span> <span style="color: #000066;">base</span>=<span style="color: #ff0000;">"tns:parentType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo1"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:int"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"demo2"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xs:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:extension<span style="font-weight: bold; color: black;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexContent<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xs:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So here the childType will inherit the &#8216;demo3&#8242; and &#8216;demo4&#8242; elements from the parent type. We will see how is the PHP generated code looks like.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">class</span> parentType <span style="color: #66cc66;">{</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$demo3</span>;

    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$demo4</span>;

<span style="color: #66cc66;">}</span>

<span style="font-weight: bold; color: #000000;">class</span> childType <span style="font-weight: bold; color: #000000;">extends</span> parentType <span style="color: #66cc66;">{</span>

    <span style="font-style: italic; color: #808080;">/**
     * @var int
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$demo1</span>;

    <span style="font-style: italic; color: #808080;">/**
     * @var string
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$demo2</span>;

<span style="color: #66cc66;">}</span></pre>
<p>It has uses the PHP inheritance to reprensent the schema inheritance. And the nice thing is you can use the childType for the places you have to use the parentType.  That is the theoy we learn at the inheritance class of other languages (Java, C++) too.</p>
<p>So say there is another complexType (say &#8220;anotherChildType&#8221;) inheriting from the type &#8220;parentType&#8221; and one another complexType (say &#8220;nextLevelChildType&#8221;) inheriting this time from &#8220;childType&#8221; (which in fact inheriting from the &#8220;parentType&#8221; as mentioned above).</p>
<p>So our types tree would be something like this.</p>
<pre>--- parentType
         |
         +-------- childType
         |              |
         |              +------------- nexLevelChildType
         |
         +-------- anotherChildType</pre>
<p>And lets say there is a schema element called &#8216;input3&#8242; with the type parentType. Then the generated variable for the input3 element will be like following code segment.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * @var (object)parentType
     *    Or one of following derived class(es)
     *       childType
     *       nextLevelChildType
     *       anotherChildType
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="color: #0000ff;">$input3</span>;</pre>
<p>This comment tells you that you can actually use the inherited types in place of the parent type according to your preferences.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/21/coding-schema-inheritance-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Online Tools for PHP Web Services Developers</title>
		<link>http://www.dimuthu.org/blog/2008/09/28/online-tools-for-php-web-services-developers/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/28/online-tools-for-php-web-services-developers/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 10:19:02 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[.dbs]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[dbs2php]]></category>
		<category><![CDATA[demo site]]></category>
		<category><![CDATA[online]]></category>
		<category><![CDATA[php2wsdl]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=401</guid>
		<description><![CDATA[PHP Web Services Demo Site contains a set of nice tools that help development of web services in PHP. WSDL2PHP tool &#8211; This allow you to generate PHP code for your WSDL. Note that this need your wsdl to be in a URL that it can access. PHP2WSDL tool &#8211; Here you can paste your [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.wso2.org/wsf/php">PHP Web Services Demo Site</a> contains a set of nice tools that help development of web services in PHP.</p>
<ul>
<li><a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">WSDL2PHP tool</a> &#8211; This allow you to generate PHP code for your WSDL. Note that this need your wsdl to be in a URL that it can access.</li>
<li><a href="http://labs.wso2.org/wsf/php/php2wsdltool.php">PHP2WSDL tool</a> &#8211; Here you can paste your annotated PHP code and get the WSDL (both version 1.1 and 2.0) generated.  You can find the annotation syntax <a href="http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html">in here</a>.</li>
<li><a href="http://labs.wso2.org/wsf/php/dbs2phptool.php">DBS2PHP tool</a> &#8211; WSO2 has Data Services library implemented in both Java and PHP. In <a href="http://wso2.org/projects/solutions/data-services/java">Java Data Services</a> you give the <a href="http://wso2.org/wiki/display/wsf/Data+Services+and+Resources">configuration via an XML</a> (in .dbs extension). Whereas in PHP you give the configuration via <a href="https://wso2.org/wiki/display/wsfphp/API+for+Data+Services+Revised">a simple PHP code which use arrays</a> to feed the configuration parameters. If you are more familiar in writing XML than PHP, you can first write the XML and then convert it to PHP using DBS2PHP tool.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/28/online-tools-for-php-web-services-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSDL2PHP 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 17:54:43 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[consumers]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[WSClient]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=349</guid>
		<description><![CDATA[WSDL2PHP makes the development of web service providers and consumers quick and easy. I wrote a 2 minutes guide on developing web services providers sometimes ago. So lets concentrate on developing web service consumers here. Where is WSDL2PHP? WSDL2PHP script is included in the WSF/PHP packs. You can find the wsdl2php.php script inside the &#8216;scripts&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>WSDL2PHP makes the development of web service providers and consumers quick and easy. I wrote a <a href="http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/">2 minutes guide on developing web services providers</a> sometimes ago. So lets concentrate on developing web service consumers here.</p>
<p><strong>Where is WSDL2PHP?</strong></p>
<p>WSDL2PHP script is included in the <a href="http://wso2.org/downloads/wsf/php">WSF/PHP packs</a>. You can find the wsdl2php.php script inside the &#8216;scripts&#8217; directory of any source or binary package. Or you can use the <a title="online wsdl2php tool" href="http://labs.wso2.org/wsf/php/wsdl2phptool.php">online wsd2php tool</a> hosted in <a title="WSF/PHP Demo Site" href="http://labs.wso2.org/wsf/php">WSF/PHP web services DEMO Site</a>.</p>
<p><strong>How to Run the Script?</strong></p>
<p>Here is the command</p>
<pre>/scripts/wsdl2php.php mywsdl.wsdl &gt; myclient.php</pre>
<p><strong>The Code is Generated. How Can I add My Code There?</strong></p>
<p>It is simple. Just search for the comment &#8220;//TODO&#8221;.<br />
Check for an example <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Flabs.wso2.org%2Fwsf%2Fphp%2Fexample.wsdl&amp;generate_type=client">here</a>.</p>
<p>You have to write custom code for 2 occasions per operation.</p>
<ol>
<li>To Provide Input Parameters</li>
<li>To Handle output parameters.</li>
</ol>
<p><strong>An Example?</strong></p>
<p>Here is the code snippet corresponding to the simpleAdd request for our <a title="Demo WSDL" href="http://labs.wso2.org/wsf/php/example.wsdl">demo WSDL</a>.</p>
<pre class="php">    <span style="color: #0000ff;">$input</span> = <span style="font-weight: bold; color: #000000;">new</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//TODO: fill in the class fields of $input to match your business logic</span>

    <span style="font-style: italic; color: #808080;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">simpleAdd</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//TODO: Implement business logic to consume $response, which is of type simpleAddResponse</span></pre>
<p>Here is how after I filled my logic in place of TODO comments.</p>
<pre class="php">    <span style="color: #0000ff;">$input</span> = <span style="font-weight: bold; color: #000000;">new</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//DONE: fill in the class fields of $input to match your business logic</span>

    <span style="font-style: italic; color: #808080;">//-------my code----</span>
    <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span> = <span style="color: #cc66cc;">2</span>;
    <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param1</span> = <span style="color: #cc66cc;">3</span>;
    <span style="font-style: italic; color: #808080;">//------------------</span>

    <span style="font-style: italic; color: #808080;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">simpleAdd</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <span style="font-style: italic; color: #808080;">//DONE: Implement business logic to consume $response, which is of type simpleAddResponse</span>

    <span style="font-style: italic; color: #808080;">//--------my code-----</span>
    <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$response</span>-&gt;<span style="color: #006600;">return</span>;
    <span style="font-style: italic; color: #808080;">//--------------------</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/21/wsdl2php-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Developing WSF/PHP Webservices With Contract First Approach &#8211; 2 Minutes Introduction</title>
		<link>http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 17:21:49 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[2 minutes]]></category>
		<category><![CDATA[contract first]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webservices]]></category>
		<category><![CDATA[wsdl2php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=237</guid>
		<description><![CDATA[WSF/PHP allows you to develop web services with both Contract First (Starting from WSDL) and Code First Approaches. From these two, Contract First approach is the most famous and most recomended way of developing a Webservice. There you need to have a WSDL to start with. I will take the http://labs.wso2.org/wsf/php/example.xml as our WSDL. Generate [...]]]></description>
			<content:encoded><![CDATA[<p>WSF/PHP allows you to develop web services with both Contract First (Starting from WSDL) and Code First Approaches. From these two, Contract First approach is the most famous and most recomended way of developing a Webservice. There you need to have a WSDL to start with. I will take the <a href="http://labs.wso2.org/wsf/php/example.xml">http://labs.wso2.org/wsf/php/example.xml</a> as our WSDL.</p>
<p><strong>Generate The Service Code</strong></p>
<p>When you download the <a href="http://wso2.org/projects/wsf/php">WSF/PHP pack </a>there is a script called &#8216;wsdl2php.php&#8217; in the script directory. Open a command line and run it with the following options. Or you can use the <a href="http://labs.wso2.org/wsf/php/wsdl2phptool.php?wsdl_url=http%3A%2F%2Flabs.wso2.org%2Fwsf%2Fphp%2Fexample.xml&amp;generate_type=server">online wsdl2php tool</a></p>
<pre>php wsdl2php.php http://labs.wso2.org/wsf/php/example.xml -s</pre>
<p><strong>Complete The Business Logic</strong></p>
<p>Complete the TODO section of the generated file. Apparently what is left to do is filling the business logic for each function corresponding to the service operations in your WSDL. You are given the hint to the input and output parameters. Here is how I fill the logic for the simpleAdd function.</p>
<pre><span style="font-weight: bold; color: #000000;">function</span> simpleAdd<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// TODO: fill in the business logic</span>
    <span style="font-style: italic; color: #808080;">// NOTE: $input is of type simpleAdd</span>
    <span style="font-style: italic; color: #808080;">// NOTE: should return an object of type simpleAddResponse</span>

    <span style="color: #0000ff;">$res</span> = <span style="font-weight: bold; color: #000000;">new</span> simpleAddResponse<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    <span style="color: #0000ff;">$res</span>-&gt;<span style="color: #006600;">return</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span> + <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param1</span>;

    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;
<span style="color: #66cc66;">}</span></pre>
<p><strong>Advanced Types? &#8211; Read Generated Hints for Class variables</strong></p>
<p>So how about filling the matrix add logic. Can be it be really complex?. No, what you need to observe is there the class member variables contains not only simple types but also another Class type. There is a comment on each member variables to hint its type. So the logic for the matrix addition is simple as this,</p>
<pre><span style="font-weight: bold; color: #000000;">function</span> matrixAdd<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// TODO: fill in the business logic</span>
    <span style="font-style: italic; color: #808080;">// NOTE: $input is of type matrixAdd</span>
    <span style="font-style: italic; color: #808080;">// NOTE: should return an object of type matrixAddResponse</span>

    <span style="color: #0000ff;">$matrix0</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param0</span>;
    <span style="color: #0000ff;">$matrix1</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">param1</span>;

    <span style="color: #0000ff;">$matrix2</span> = <span style="font-weight: bold; color: #000000;">new</span> Matrix<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$matrix2</span>-&gt;<span style="color: #006600;">rows</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matrix0</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">)</span> == <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matrix1</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span> <span style="font-style: italic; color: #808080;">// considering only happy path</span>

        <span style="color: #b1b100;">for</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span> &lt; <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$matrix0</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$i</span> ++ <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

            <span style="color: #0000ff;">$row0</span> = <span style="color: #0000ff;">$matrix0</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">]</span>;
            <span style="color: #0000ff;">$row1</span> = <span style="color: #0000ff;">$matrix1</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">]</span>;

            <span style="color: #0000ff;">$row2</span> = <span style="font-weight: bold; color: #000000;">new</span> MatrixRow<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
            <span style="color: #0000ff;">$matrix2</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$row2</span>;
            <span style="color: #0000ff;">$row2</span>-&gt;<span style="color: #006600;">columns</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

            <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row0</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">)</span> == <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row1</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

                <span style="color: #b1b100;">for</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$j</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$j</span>&lt; <a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row0</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">)</span>; <span style="color: #0000ff;">$j</span> ++ <span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

                    <span style="color: #0000ff;">$col0</span> = <span style="color: #0000ff;">$row0</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">]</span>;
                    <span style="color: #0000ff;">$col1</span> = <span style="color: #0000ff;">$row1</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">]</span>;

                    <span style="color: #0000ff;">$col2</span> = <span><span style="color: #0000ff;">$col0 </span></span>+ <span><span style="color: #0000ff;">$col1</span></span>;

                    <span style="color: #0000ff;">$row2</span>-&gt;<span style="color: #006600;">columns</span><span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$col2</span>;
                <span style="color: #66cc66;">}</span>
            <span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span>

    <span style="color: #0000ff;">$res</span> = <span style="font-weight: bold; color: #000000;">new</span> matrixAddResponse<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$res</span>-&gt;<span style="color: #006600;">return</span> = <span style="color: #0000ff;">$matrix2</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;
<span style="color: #66cc66;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/08/developing-wsfphp-webservices-with-contract-first-approach-2-minutes-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
