Chapter 15. Proxy Pattern

My first foray into the world of AJAX was filled with both exciting triumphs and frustrating moments. I stumbled across this new technology that was going to revolutionize the way that I designed and created my web pages. I was so excited to be able to use this tool to move from web pages to web applications. The first thing I attempted to do was make a mash-up of weather and upcoming bands. I wanted to know if I went to an outdoor show, if I'd need a jacket. I initially designed the project to read the XML feeds using PHP on the server side. Once I knew it could be done, I wanted to migrate the functionality to the browser side so I could take advantage of the cool effects of the AJAX object. As you probably know, I ran into a snag right away. The XML feeds would just not load with my AJAX request. The XMLHttpRequest object was not able to load cross-site requests. It wasn't immediately clear to me how I could accomplish retrieving this data from these remote sites. Finally, I came across the solution, which involved designing a proxy PHP object to retrieve the remote data and provide it locally. When working with data and objects that require special attention or access considerations, the Proxy Design Pattern can help.

Name: Proxy

The Proxy Design Pattern builds an object that is positioned transparently within two other objects in order to intercept or proxy the communication or access.

Get Professional PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.