<?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>Matthew Turland &#187; Tokenizer</title>
	<atom:link href="http://matthewturland.com/tag/tokenizer/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewturland.com</link>
	<description></description>
	<lastBuildDate>Sun, 18 Jul 2010 14:29:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Splitting PHP Class Files</title>
		<link>http://matthewturland.com/2010/01/22/splitting-php-class-files/</link>
		<comments>http://matthewturland.com/2010/01/22/splitting-php-class-files/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 23:26:29 +0000</pubDate>
		<dc:creator>Matthew Turland</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Tokenizer]]></category>
		<category><![CDATA[WSDL]]></category>

		<guid isPermaLink="false">http://matthewturland.com/?p=94</guid>
		<description><![CDATA[A recent work project required me to write a PHP script to interact with a remote SOAP service. Part of the service provider&#8217;s recommended practices entailed using a slightly dated software package called wsdl2php, which generates a single PHP file containing classes corresponding to all user-defined types from a specified WSDL file. The issue I ran into [...]]]></description>
			<content:encoded><![CDATA[<p>A recent work project required me to write a PHP script to interact with a remote <a title="SOAP - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/SOAP_(protocol)">SOAP</a> service. Part of the service provider&#8217;s recommended practices entailed using a slightly dated software package called <a title="wsdl2php | Get wsdl2php at SourceForge.net" href="http://sourceforge.net/projects/wsdl2php/">wsdl2php</a>, which generates a single PHP file containing classes corresponding to all user-defined types from a specified <a title="Web Services Description Language - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Web_Services_Description_Language">WSDL</a> file.</p>
<p>The issue I ran into was due to all the generated PHP classes being housed in a single file. I had to process two WSDL files that had several identical user-defined types in common. As a result, I couldn&#8217;t simply include the two PHP files generated from them because PHP doesn&#8217;t allow you to define two classes with the same name.</p>
<p>Looking at its source code, modifying wsdl2php to change this behavior was not a very appealing option. Attempting to consolidate the two WSDL files into one with no redundant user-defined type declarations seemed futile as well. Instead, I resolved to split the generated PHP files such that each class was contained in its own file. This would also allow me to use an autoloader to determine which of the classes I actually needed for the particular service call I was making.</p>
<p>Due to the number of classes, splitting the classes into separate files by hand would have been tedious and time-consuming. I decided to tap into my <a title="Coding Standard Analysis using PHP_CodeSniffer | Blue Parabola, LLC" href="http://blueparabola.com/blog/coding-standard-analysis-ing-phpcodesniffer">previous experience</a> with the <a title="PHP: Tokenizer - Manual" href="http://php.net/tokenizer">tokenizer extension</a> to throw together a CLI script that would handle this for me. Once I got it working, it clocked in at just over 50 <acronym title="Lines of Code">LOC</acronym> with comments and whitespace. You simply call it from a shell and pass it the PHP file you want to split and the destination for the split class files.</p>
<p>I thought it might be useful for others needed to process similarly formatted source code, so I threw it into a <a title="php-class-splitter.php at master from elazar's php-class-splitter - GitHub" href="http://github.com/elazar/php-class-splitter/blob/master/php-class-splitter.php">github repository</a> for anyone who might like to take a look. I&#8217;m open to suggestions for improvements to implement if enough people find it useful. Feel free to file an issue on the repository if you happen to find a bug.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewturland.com/2010/01/22/splitting-php-class-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
