<?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; schema</title>
	<atom:link href="http://www.dimuthu.org/tag/schema/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>WSF/PHP Test Cases Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 19:27:10 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[phpt]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[rm]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[test-suit]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[wsdl generation]]></category>
		<category><![CDATA[wsdl mode]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=594</guid>
		<description><![CDATA[WSO2 WSF/PHP comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the &#8220;src/tests&#8221; directory of WSF/PHP source package. Or you can find the latest test-suite from the SVN location. Here are some aspects covered in the test-suit. Scenario [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the &#8220;src/tests&#8221; directory of WSF/PHP source package. Or you can find the latest test-suite from <a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">the SVN location</a>.</p>
<p>Here are some aspects covered in the test-suit.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Scenario</td>
<td>Test Cases For Client</td>
<td>Test Cases For Service</td>
</tr>
<tr>
<td>Basic Functionality</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_client*.phpt</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">math_*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/echo_service*.php</a><br />
<a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/math_service.php</a></td>
</tr>
<tr>
<td>Basic Schema Types</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/BasicDataTypes/">BasicDataTypes/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/BasicTypesDoclitBSvc/">services/BasicTypesDoclitBSvc/*.php</a></td>
</tr>
<tr>
<td>Complex Schema Types</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/cmplxDataTypes/">cmplxDataTypes/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/ComplexDataTypesWSvc/">services/ComplexDataTypesWSvc/*.php</a><br />
<a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/ComplexDataTypesBSvc/">services/ComplexDataTypesBSvc/*.php</a></td>
</tr>
<tr>
<td>WSDL/Schema Variations</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_mode/">wsdl_mode/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunhttps://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_mode/">services/wsdl_mode/*.php</a></td>
</tr>
<tr>
<td>WSDL Generation with Annotations</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/wsdl_generation/">wsdl_generation/*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/wsdl_generation/">services/wsdl_generation/*.php</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_rm*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/">samples/echo_service_rm*.php</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_encrypt_client*.phpt</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_signing_client*.phpt</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_timestamp_client*.phpt</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">echo_username_token_client*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">encrypt_service*.php</a><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">signing_service*.php</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">timestamp_service*.php</a></p>
<p><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/services/">username_token_service*.php</a></td>
</tr>
<tr>
<td>MTOM</td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/src/tests/samples/">mtom_*.phpt</a></td>
<td><a href="https://wso2.org/repos/wso2/trunk/wsf/php/samples/mtom/">samples/mtom/*.php</a></td>
</tr>
</tbody>
</table>
<p>(Note that Here &#8216;*&#8217; is used as a wild card represent 0 or many characters)</p>
<p><strong>Steps to Run Tests</strong></p>
<ul>
<li>First you need to install WSF/PHP correctly. Please read the <a href="http://wso2.org/project/wsf/php/2.0.0/docs/manual_content.html#Installation">WSF/PHP installation manual</a> for that.</li>
<li>You have to have the &#8216;pear&#8217; utility tool comes with PHP. And add this to the PATH environment variable.</li>
<li>Copy the samples and src/tests/samples/services directory (paths are relative to the root directory of the wsf/php package) to the web root directory.</li>
<li>Then go to the src/tests directory and execute the following command.
<pre>pear run-tests -r</pre>
<p>This will execute all the test cases under the &#8216;tests&#8217; directory and finally give a summery of the test results.</li>
<li> You can run individual test cases separately by providing the relative path to the test case from the &#8216;test&#8217; directory. E.g. To run the echo_client.phpt test case, you may type
<pre>pear run-tests samples/echo_client.phpt</pre>
</li>
</ul>
<p>If you like to add test cases for the WSF/PHP scenarios, follow this comprehensive guideline titled <a href="http://wso2.org/library/3579">Writing Simple phpt Test Scripts For PHP Web Services</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/11/wsfphp-test-cases-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSDL Generation From PHP &#8211; Using Different Names in WSDL and PHP Code</title>
		<link>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 14:01:24 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></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[class]]></category>
		<category><![CDATA[classmap]]></category>
		<category><![CDATA[different]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[operation]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php2wsdl]]></category>
		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=535</guid>
		<description><![CDATA[PHP2WSDL feature of the WSF/PHP allows you to generate the WSDL for your service when you access the URL formed by adding &#8220;?wsdl&#8221; to the service URL ( or you can use service URL + &#8220;?wsdl2&#8243; to access the wsdl version 2.0). It will generate the schema types for the wsdl from the classes you [...]]]></description>
			<content:encoded><![CDATA[<p>PHP2WSDL feature of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> allows you to generate the WSDL for your service when you access the URL formed by adding &#8220;?wsdl&#8221; to the service URL ( or you can use service URL + &#8220;?wsdl2&#8243; to access the wsdl version 2.0). It will generate the schema types for the wsdl from the classes you use to build the request message + the annotations you provided describing the types of the variables.</p>
<p>Sometime you may need to generate schema types with different names to the corresponding PHP classes. May be you need to have a &#8216;-&#8217; in the schema type which is not valid in PHP class syntax or you like to have a different naming convention for PHP and wsdl.  Similarly you may need to have the operation names different in the WSDL and the PHP code.</p>
<p>Here is how you do it with WSF/PHP.</p>
<p><strong>Different Names for Operations<br />
</strong></p>
<pre class="php"><span style="font-style: italic; color: #808080;">/**
 * Service logic for the echo operation
 * @namespace http://ws.dimuthu.org/php/myecho/operations
 * @param object testObject $param
 * @return object testObject $return
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> echoMe<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$param</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$param</span>;
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">/* The Service operation name to PHP function name map */</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echo"</span> =&gt; <span style="color: #ff0000;">"echoMe"</span><span style="color: #66cc66;">)</span>;</pre>
<p>There I want my actual operation name to be echo. But I can&#8217;t declare a function name echo since PHP already has a library function echo (Yea, the one you regularly use to echo output). So I don&#8217;t have option other than declaring a function with different name (here it is &#8220;echoMe&#8221;) and mapped it in to echo operation in the operation map. We are going to feed this $operation variable at the WSService creation as its constructor argument.</p>
<p>Lets see how different names are used in schema types and corresponding php class names.</p>
<p><strong>Different names for Types and Classes<br />
</strong></p>
<pre class="php"><span style="font-style: italic; color: #808080;">/**
 * @namespace http://ws.dimuthu.org/php/myecho/types
 */</span>
<span style="font-weight: bold; color: #000000;">class</span> testObject <span style="color: #66cc66;">{</span>

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

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

<span style="font-style: italic; color: #808080;">/* The mapping of schema types to PHP class */</span>
<span style="color: #0000ff;">$classmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"test-object"</span> =&gt; <span style="color: #ff0000;">"testObject"</span><span style="color: #66cc66;">)</span>;</pre>
<p>It is similar how we mapped operation in the previous section. Just use $classmap variable which map the schema type name to the php class name.</p>
<p>Here is the type section and the interface section of the WSDL 2.0 generated using above codes. Observe the operation names and the types names are formed the way we expected.</p>
<pre class="xml">  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;types<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:schema</span> xmlns:ns0=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</span>
        xmlns:ns1=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</span>
        <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">"qualified"</span>
        <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/operations/xsd"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:import</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"param"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"ns0:test-object"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"return"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"ns1:test-object"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:schema<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:schema</span> <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">"qualified"</span></span><span><span style="color: #009900;">
               </span></span><span style="color: #009900;"> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">"http://ws.dimuthu.org/php/myecho/types"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"test-object"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"aint"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:integer"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
          <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"astring"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:schema<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/types<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"myEchoPortType"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"echo"</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">"http://www.w3.org/ns/wsdl/in-out"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;input</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"tnx:param"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
      <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;output</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">"tnx:return"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/interface<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>Here is the complete code (Combining all the previously mentioned code segments). You can check the complete wsdl generation (wsdl  1.1 or wsdl 2.0 as your preference) by copying and pasting this code to the <a href="http://labs.wso2.org/wsf/php/php2wsdltool.php">online php2wsdl generator</a> at the <a href="http://labs.wso2.org/wsf/php">WSF/PHP Demo Site</a>.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-style: italic; color: #808080;">/**
 * Service logic for the echo operation
 * @namespace http://ws.dimuthu.org/php/myecho/operations
 * @param object testObject $param
 * @return object testObject $return
 */</span>
<span style="font-weight: bold; color: #000000;">function</span> echoMe<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$param</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$param</span>;
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">/**
 * @namespace http://ws.dimuthu.org/php/myecho/types
 */</span>
<span style="font-weight: bold; color: #000000;">class</span> testObject <span style="color: #66cc66;">{</span>

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

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

<span style="font-style: italic; color: #808080;">/* The Service operation name to PHP function name map */</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echo"</span> =&gt; <span style="color: #ff0000;">"echoMe"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* Telling that we input MIX types for the parameters */</span>
<span style="color: #0000ff;">$opParams</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echo"</span> =&gt; <span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* The mapping of schema types to PHP class */</span>
<span style="color: #0000ff;">$classmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"test-object"</span> =&gt; <span style="color: #ff0000;">"testObject"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">/* Creating the WSService and serving the Request */</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			<span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
			<span style="color: #ff0000;">"classmap"</span> =&gt; <span style="color: #0000ff;">$classmap</span>,
			<span style="color: #ff0000;">"opParams"</span> =&gt; <span style="color: #0000ff;">$opParams</span>,
			<span style="color: #ff0000;">"serviceName"</span> =&gt; <span style="color: #ff0000;">"myEcho"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/23/wsdl-generation-from-php-using-different-names-in-wsdl-and-php-code/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[web services]]></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[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>
	</channel>
</rss>

