Dr. Dobb's Journal - January 2008 - (Page 58) d01gutm_p4ma 11/12/07 8:16 AM Page 58 Core Technology PHP: THE POWER BEHIND WEB 2.0 Articles.getEventBus().addObserver (newRequestWatcher ('requestCount'),'requests'); Now let’s take a look at the EventBus.js code (available online). Whenever we want to fire an event, we call EventBus.notify() with a message (or event name) and a payload. The message is used to determine which observers to notify. When registering an observer, you specify two parameters—an instance of the observer itself and the message to subscribe to. Outside of its constructor, RequestWatcher.js (available online) implements the single method, notify(). Notify takes the payload, in this case the number of remaining requests, and updates the output container with it. When we instantiated it in pageLoad(), the parameter we handed it was requestCount. This corresponds with the ID of a span tag in the HTML to be updated. Recap! By selecting the right tools for the job, even a three-way mash-up like this can be thrown together quickly. In the case of FNN, we chose the Zend Framework as the base because it contains all the pieces we needed to get our service written quickly. Additionally, because of the way the Zend Framework is structured, we were able to easily pull out the pieces we wanted and use them independently. The other piece we selected was Prototype.js. Prototype’s light footprint and simple interface let us quickly put the JavaScript together. Second, by using good object-oriented techniques and practices, the server-side piece is now a framework that can be extended to consume resources from other services by building new Proxy classes. On the client side, the OO is a bit more difficult because of language limitations, but we adhere to OO design theory whenever possible. That lends itself to well-segregated code. Figure 1: The Flicker News Network architecture. Finally, the one unspoken concept we covered—building web services, even services that consume other’s services, is painless. FNN talks to a simple PHP page named “service.php,” which consumes other’s services, but also publishes its own service. It converts the data from our news feeds, Yahoo, and Flickr, into an easily digestible format. With the tools we’ve examined, you can now easily find the unique data or service that you have and build a service around it. DDJ 58 Dr. Dobb’s Journal l www.ddj.com l January 2008 http://www.sqljunkies.com http://www.dotnetjunkies.com http://www.sqljunkies.com http://www.dotnetjunkies.com http://www.ddj.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.