SWX Alpha 0.1.9 Released

SWX: New, friendlier welcome page -- although it's early days yet.

My goodness, it's been eight whopping days since the last release of SWX -- no wonder I was getting antsy! SWX Alpha version 0.1.9 is now available for download... and what a release this one is too! :)

Amfphp interoperability

The major new feature is that SWX is now interoperable with Amfphp. In fact, the latest release contains Amfphp 1.9.2 (the latest public release of Amfphp.) This was a core design goal from the outset for me and, with a little nudge in the right direction by Patrick (thanks, man), I'm very happy that it's implemented.

What does all this mean?

Well, it means that you can use the same service classes in both Amfphp and SWX. The current limitation is that methods that return RecordSets are not supported in SWX. So let's put this into perspective. This means that with the latest release of SWX, you can write a single service class in PHP that has methods that return arrays of objects and then expose this single class as SWX, JSON, XML-RPC or Flash Remoting without re-writing anything. IMHO, that's pretty awesome! :)

Do you want SWX? Hit the SWX gateway (swx.php). Would you rather have your data as JSON, sir? Sure! Hit the JSON gateway (json.php). No, you want XML-RPC? Hit (xmlrpc.php). And if you want Flash Remoting, well, just hit the AMF gateway (amf.php). Sweet!

SWX Analyzer + PHP Service Browser = Major Yummm!

It also means that in addition the SWX analyzer, you can now also use the PHP Service Browser from Amfphp. And they're a great combination too!

Here's a sample workflow:

First, let's build a PHP service class:

  1. Create a service class (in the php/services/ folder). e.g., MyFirst.php
  2. Create a method in your class that returns a value. e.g., helloWorld()

The PHP service class in the above example looks like this:

Now open the PHP Service Browser (it's in the php/browser/ folder). You will see the MyFirst class. Click it and you will see the helloWorld() method. Click the Call button to invoke the method. You'll see the returned value, as shown in the screenshot below.

PHP Service Browser in SWX

The PHP Service browser is great for debugging your service classes as you build them.

Next, build a simple Flash client that uses SWX to connect to the SWX gateway.

  1. Create a new FLA and save it in the flash/examples folder. e.g., helloworld.fla.
  2. Create a movie clip on the main timeline and give it the instance name dataHolder.
  3. On the first frame, set the name of the service class and the method you want to call from PHP. In this case, the class is MyFirst and the method is helloWorld. If the helloWorld() method took arguments, you would specify those too but this simple method doesn't take any.
  4. Set the debug property on the dataHolder to true so that you see debug information in the SWX Analyzer
  5. Use loadMovie() to call the SWX gateway

The code in the example above looks like this:

import org.swxformat.*;

dataHolder.serviceClass = "MyFirst";
dataHolder.method = "helloWorld";
dataHolder.debug = true;

dataHolder.loadMovie("http://localhost:8888/php/swx.php", "POST");

Run the SWX Analyzer (it's in the php/analyzer/ folder) using the standalone Flash Player before testing your movie and you should see "Hello, World!" appear in it when you do, as shown in the screenshot below.

SWX Analyzer hello world

The SWX Analyzer is a great tool for seeing the data that is actually returned to your Flash client.

This latest version of the SWX Analyzer brings with it a History Panel. This panel holds a list of all data exchanges and you can go back to previously received data packets at any time. When you're viewing historical data, new packets will continue to come in and you can go back to having the interface automatically display the latest packet by clicking the latest packet in the History Panel. Cool, no?

The SWX Analyzer and PHP Service Browser combined give you a great deal of visibility into your projects and make it easier to test them.

New sample apps

Beyond these changes, I've also added the two Twitter applications and the Twitter service class to this release. The code in these samples is in no way cleaned up so don't take it as recommended practice in any way. I just thought it would be good to give you something to play with earlier rather than later.

Configurable services folder

Also, you can now configure the folder in which your services are held by editing the swx_config.php file in the php/ folder. Amfphp will also use this service folder so you do not have to separately configure it (in fact, do not edit the Amfphp globals.php file manually unless you know what you're doing.)

Better docs

It's very early days but I'm beginning to focus on making the documentation and the start page friendlier. Expect continuous improvements on both these fronts in future releases.

Better PHP compatibility

I tested this release with MAMP 1.4.1, which has PHP 4.4.4 and updated it to work with this version. So, in addition to PHP 4.1.4 and 5.1.2, PHP 4.4.4 has now been tested too. If you have success in running it under other versions of PHP, please do let me know.

Download SWX Alpha version 0.1.9.

Enjoy and remember to have fun with it all! :)

Comments