Martin Probst's weblog

PHP Soap "code generator"

Thursday, November 9, 2006, 12:01 — 3 comments Edit

I somehow tragically got into a project where we need to access fairly complicated SAP WebServices from PHP using SOAP. PHP provides the SoapClient class, but there is apparently no way to generate code from WSDL files to make your life easier. I created two small tools to help me with that, one to make a WSDL definition browsable, another one to somehow generate PHP code from the WSDL.



if (isset($argv[1])) { $wsdl = $argv[1]; } else if (isset($_GET[“wsdl”])) { $wsdl = $_GET[“wsdl”]; } else { echo ‘<form method=“GET” action=“’ . $_SERVER[“PHP_SELF”] . ‘”>’ . “\n”; echo ‘Specify a WSDL to dump: <input name=“wsdl” type=“text”/></form>’; exit(0); }

// replace word character groups delimited by non-words with a hrefs to #word function hrefify($str) { return preg_replace(‘/(\\W)?(\\w+)(\\W)?/‘, ‘\\1<a href=\’#\\2\‘>$2</a>\\3’, $str); }

$options = $SAP_AUTH; try { $soap = new SoapClient($wsdl, $options); echo “<h1>$wsdl</h1>”; echo “<h2>Types:</h2>\n”; echo “<pre class=“prettyprint”>\n”; foreach($soap->getTypes() as $name => $type) { preg_match(‘/\w+ (\w+)/‘, $type, $matches); $name = $matches[1]; echo “<h4><a id=‘$name’>$name</a></h4>\n”; echo hrefify($type); } echo “</pre>\n”; echo “<h2>Functions:</h2>\n”; echo “<pre class=“prettyprint”>\n”; foreach($soap->getFunctions() as $name => $func) { preg_match(‘/\w+ (\w+)/‘, $type, $matches); $name = $matches[1]; echo “<h4><a id=‘$name’>$name</a></h4>\n”; echo hrefify($func); } echo “</pre>\n”; } catch (SoapFault $f) { echo $f; } ?>


 * Use to transform the types in a given WSDL file to PHP classes.
 * <p>
 * Think of this as a really poor code generator…


if (isset($argv[1]) && $argv[1] != “”) { $wsdl = $argv[1]; } else if (isset($_GET[“wsdl”]) && $_GET[“wsdl”] != “”) { $wsdl = $_GET[“wsdl”]; } else { echo ‘<form method=“GET” action=“’ . $_SERVER[“PHP_SELF”] . ‘”>’ . “\n”; echo ‘Specify a WSDL to transform to PHP: <input name=“wsdl” type=“text”/></form>’; exit(0); }

$options = $SAP_AUTH; $actual_types; try { $soap = new SoapClient($wsdl, $options); echo “<pre class=“prettyprint”>\n”; echo “&lt;?php\n”; echo “// This file was generated from $wsdl using create_types.php\n\n”; $types = $soap->__getTypes(); foreach($types as $type) { if (preg_match(“/^struct./“,$type)) { // this is a complex type preg_match(‘/struct (\w+)/‘, $type, $matches); $name = $matches[1]; $actual_types[$name] = $name; echo “class $name {\n”; $lines = array_slice(explode(”\n”, $type), 1, -1); foreach ($lines as $line) { $line = preg_match(‘/ (\w+) (\w+);/‘, $line, $matches); $subtype = array_values(preg_grep(“/^\w+ $matches[1]/“, $types)); if (isset($subtype[0]) && !preg_match(“/^struct./“,$subtype[0])) { // primitive type echo “ // ” . $subtype[0] . “\n”; } else { echo “ // ” . $matches[1] . “\n”; } echo “ public \$$matches[2];\n”; } echo “}\n\n”; } } echo “\$classmap = array(\n”; while (list($name, $class) = each($actual_types)) { echo “ \”$name\” => \”$class\”“; if (current($actual_types)) { echo “,”; } echo “\n”; } echo “);\n”; echo “?>”; echo “</pre>\n”; } catch (SoapFault $f) { echo $f; } ?>

Mighty right clicks

Sunday, October 22, 2006, 17:41 — 0 comments Edit

I tried the Mighty Mouse, and now I tried the wireless Mighty Mouse. It’s totally impossible for me to reproducibly right click with them. I always manage to actually get a right click from the mouse, but quite often only on the third attempt. This really sucks, it’s both unnerving and unsafe (in situations where a left click means something dramatically different from right click). I heard from others they are fine with the mouse … strange.

Anyways, I’ll rather go with Logitech as in the past. Initially I wanted to get a Bluetooth mouse, but I now figured that wireless gives me close to nothing - if the cable annoys you it’s simply time to tidy your desktop and get the blocking things out of the way :-) - and I’d need to worry about batteries. Plus the higher price of course.

Safari auto-completion magic?

Tuesday, October 17, 2006, 06:42 — 0 comments Edit

Some seconds ago I filled out a form on some website and it had one of those (not really) Turing tests, in this case the question was: “Math question, take (5 - 1) and divide by two”.

To my big surprise, when I entered my name Safari auto completion kicked in, filled out the rest of the fields (telephone etc.) including the test question with “2”!

Probably totally random luck as this auto completion feature is actually quite buggy, I find myself deleting wrongly filled out entries more often than using it, but I was really shocked :-)

Programming language features

Friday, October 13, 2006, 09:49 — 0 comments Edit

Joel Spolsky reviews “Beyond Java”:

Programming consists of overcoming two things: accidental difficulties, things which are difficult because you happen to be using inadequate programming tools, and things which are actually difficult, which no programming tool or language is going to solve. An example of an accidental difficulty is manual memory management, e.g. “malloc” and “free,” or the singleton classes people create in Java because they don’t have top level functions. An example of something which is actually difficult is dealing with the subtle interactions between different parts of a program, for example, figuring out all the implications of a new feature that you just added.
I’m not so sure this is correct, at least the example is quite bad. Managing the subtle interactions between different parts of a program can be made a lot easier by programming language features. That, and particular programming styles (aka patterns), but most of those are only enabled by programming language features.

For example, the Model-View-Controller pattern eases managing the interaction between parts of your application, and it’s near impossible without an object oriented programming language. Or encapsulation of data types, which reduces the impact of modifying the actual (physical) data representation on the rest of the program. Or polymorphism, which eases adding additional data types.

I think this list goes on, and also spreads into other areas of programming. For example generators (“yield”) in python.

Programming language features enable us to use/invent new patterns, which in turn make programming easier. There are hard problems and they will probably stay hard, but certain programming techniques can make them at least a bit easier (ie. look at the new java.util.concurrent libraries for Threading).

Time for new HTML Validator?

Wednesday, August 16, 2006, 09:35 — 0 comments Edit

Sam Ruby (author of the excellent feed validator) asks this question.

I think the problem is not really with the validator not detecting bugs, it’s more about the fact that nobody really cares to look at it. I don’t think the situation can be fixed by providing a better validator. There is just no short term, visible benefit in making pages conformant (except maybe bragging in front of your friends).

Nothing will make people invest time (= money) into fixing their pages if they don’t get anything in return. There is no use case for conforming and valid pages, everything we do today works with invalid pages.

I think the only thing that would make webpages better would be the advent of a new technology that would crucially require valid webpages. However, noone will design such a technology, as anyone knows that all the pages on the web are invalid …

The only thing that can be done is avoiding the same mistakes with XML and e.g. ATOM feeds. Don’t consume incorrect feeds, so that people notice if their feeds are broken. Otherwise we’ll end up with something like HTML is today: building any app consuming HTML is unbelievably expensive and tedious, because all of the available HTML is broken. We should avoid this for XML, even if it means a little more expenses for the producers at the beginning.

The oppsite of a Virtual Files System - the Dumb FS

Wednesday, August 9, 2006, 08:57 — 0 comments Edit

Many development platforms implement a virtual file system. The basic idea is that you abstract away the actual location, access methods etc. of files to provide a coherent view to applications on top of that. These virtual file systems then provide some sort of hooks or plugin mechanism to allow others to extend this VFS.

Now the great extensibility platform Eclipse takes a surprising approach at this. It kind of goes in the opposite direction and implements a DumbFS. Everything useful needs to be a Resource in Eclipse, and a Resource does not only have to be a local file, it also needs to be in a project, which needs to be in the workspace.

But wait, there are non-local resources! See the great level of abstraction! From the JavaDocs of IResource:

* Phantom resources represent incoming additions or outgoing deletions
* which have yet to be reconciled with a synchronization partner.
Did someone say CVS? Anyways, non-local resources have the interesting property that they are like resources, except completely useless because no IO is possible on them. So if you want to work on files, they need to be local, and in a project, in your workspace. Anything else is black magic and evil, so it got abstracted away.

Now, this is kind of sad, especially as Eclipse tries to reach beyond IDE stuff with the Rich Client Platform (RCP), and it’s really sad if you can’t do anything with files in there. But no problem, there is an example of how you create a RCP text editor. Of course, actually using the Text Editor component (part of RCP!) is such a special use case, you will have to do some coding on your own. In the example, this is ~500 LOCs, not counting anything Text Editor or application related, only the file access stuff, over 3 classes and one XML file (they didn’t expect that people might want to open files, so you have to extend the platform to provide that advanced feature). Oh and of course you don’t end up with a plain Eclipse text editor, several features wont work because it doesn’t have it’s beloved Resources.

I’ve always wondered why it’s so difficult in Java to open and read a file, but these guys play in a whole different league. Provide a text editor component, but then require every user of it to write his or her own file handler. Provide an advanced application development framework, but require anyone who wants to open a file to do some black magic adding an “Open file” command to the platform. Great stuff.

Should developers write their own tests?

Wednesday, August 9, 2006, 07:47 — 0 comments Edit

Dare Obasanjo wonders if having your developer team do the testing and operations, too, is actually such a great thing. I’m not sure about operations/deployment, I’ve never worked in a company that does any serious deployment.

However regarding test teams the major problem with a lot of people is that they don’t make a clear distinction between source level Unit Tests (as in Test Driven Development), which is something only the developer can do. And then there is this completely different thing called end-to-end test or function tests. There you test your application (not the source code!) against a specification - either an explicit, proper one, or an implicit, informal one. This is probably best done by real test engineers.

If you can afford to do both, you should certainly do so. Unit Tests are a great development and productivity tool, they make you write better code faster. End-to-end tests are what your customers actually want and need, they assure the product is working as advertised, so you certainly have to do that, in one way or the other.

Telekom rant

Monday, August 7, 2006, 14:27 — 0 comments Edit

I’m currently trying to get a telephone/DSL connection for my new flat in Potsdam. There are 3 real providers available, Telekom (ex-monopolist), Arcor and Alice. Both Arcor and Alice offer unlimited calls to fixed networks in Germany and unlimited DSL access (6 MBit) for about 50 Euros. Arcor requires a 24 month contract, so I’ll probably go with Alice.

The funny thing is I wanted to compare this with Telekom’s prices, and I just can’t. Their website has 5 different fixed line contracts, plus three options for those (one with a monthly fee, two with minimum charges), plus four different DSL connections (some with a setup price, some without), some of those include VoIP, plus the DSL flatrate. All of these include some sort of teaser things for their hotspot network and other services.

Plus, there is this brand new thing called T-One, which somehow integrates a mobile phone with a fixed line and DSL. No idea how much that is, or how much calling ist etc. because the prices are apparently secret - you may only see them if you registered with the Telekom website.

Speaking of website, the Telekom company has decided to split up into several business sectors. This means that if you want to get a telephone line and find out how much it will be, you typically visit 3-4 different TLDs (,, plus various etc.). So every second click opens a new window. The motivation is probably that the managers of the single divisions feel more important like that. Completely ridiculous. It seems they just don’t want to have customers. And they even joke on you - every second tag line on their website says “Easy and fast”, they’ve probably had one hell of a time writing that.

In addition to that - I’m not sure, but this is my guess - it seems at Telekom I’d end up with about 60 something Euros for an analogue telephone line, a DSL 2 MBit flat and no telephone flat, for an unknown setup price. Now that’s a competitive price.

There is a VoIP product available from GMX, but it requires a Telekom fixed line (requiring setup) and ends up at 51,94 including the telephone flat. So basically it’s about the same price as a normal line with Alice/Arcor, but you also have the hassle with two companies and the new technology. No thanks.

More proof that XML Schema is A Bad Thing (tm)

Wednesday, July 12, 2006, 09:41 — 0 comments Edit

I’m currently converting the XQuery Update Facility Use Cases into our XML format to use them as preliminary test cases for X-Hive’s implementation.

The use cases include several tow test documents that have schema information. Both are invalid in my schema editor (<oXygen/> XML editor) - one because of the order of elements (attribute definitions after sequence in a complexType), the other because something doesn’t work with qualified element names and “ref”erences to elements in the schema. I’m not an expert on XML Schema (thank God) so I don’t know whether it’s my processor that’s wrong or the documents.

The error messages of the tool were something like “there is something wrong here”, or alternatively misleading (“components without a namespace cannot be imported from document ….xsd”, but it’s not at all about the document, apparently), so it’s been quite annoying to fix.

The same document set includes three files with a DTD, all of them work.

X-Hive 8.0 will probably have support for RELAX NG, so there is some bright light at the end of the tunnel.

The ability to say no

Tuesday, June 20, 2006, 07:11 — 0 comments Edit

Some time ago I commented on Uche Ogbuji describing XQuery as too complex. Now Dare Obasanjo writes this:

The lessons listed above seem rather self evident and obvious yet it s a sad fact of the software industry that the mistakes of CORBA keep getting made all over again. Core XML technologies like W3C XML Schema and XQuery are ‘standards’ without a reference implementation which invented new features by committee instead of standardizing best practice.

I won’t comment on XML Schema, but of course I’ll have to defend XQuery :-)

Dare’s criticism is partially right, XQuery apparently had some problems with the innovation by commitee thing, which has bloated the spec significantly and delayed it a lot. However XQuery (and XSLT 2.0 and the related specs) do have an inofficial reference implementation, it’s Michael Kay’s Saxon. It also has a very good test suite (which just got even better due to the tests from the KDE guys) and the results show that there are at least three implementations taking very different approaches that manage to cover most of XQuery correctly. XQuery is an existing, working technology with support from major industry players and a lot of implementations.

I think the major problem with CORBA was it’s huge complexity for the user. This really doesn’t compare with XQuery, which may be complicated to implement, but it’s really trivial to use. Dare quotes a list of important traits a spec should have, originally from Michi Henning:

5. To create quality software, the ability to say “no” is usually far more important than the ability to say “yes.”.

This is something XQuery gets exactly right. You can use it directly, without XML Schema, without static, strict or any typing at all, without validation, without functions etc. Every feature is optional to the user and invisible if unused.

It’s quite important to look at XQuery how it is lately - use one of the implementations or at least take a look at the spec, the implementations and all. If you’re just looking at the time from the first WD (which is indeed a legit complaint), you might get the impression of failure all over, but I don’t think XQuery is going to be the next XML Schema.

New Post