Home arrow PHP arrow Page 5 - Introducing the Facade Pattern in PHP 5

Seeing the facade pattern in action - PHP

The facade pattern may be one of the less well known patterns in PHP, but it definitely has its uses. In this first article of a two-part series, you'll learn the basics of how the facade pattern works, illustrated with numerous examples.

TABLE OF CONTENTS:
  1. Introducing the Facade Pattern in PHP 5
  2. A basic implementation of the facade pattern
  3. Using HTTP compression with PHP 5
  4. Completing the facade schema
  5. Seeing the facade pattern in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
January 16, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As I said before, below I developed a comprehensive example that demonstrates how the facade pattern can be used for compressing the HTTP output of a specific web page, in this case by using all the classes that were created previously. Please take a look at the following code sample:

// example using 'CompressContentFacade' class
try{
   // instantiate 'WebPage' object
   $webPage=new WebPage('This is the sample title for the
compressed web page','keyword 1,keyword 2,keyword 3');
   // create web page header section
   $webPage->makeHeader();
   // create web page body section
   $webPage->makeBody('This is a sample content for the
compressed web page');
   // create web page footer section
   $webPage->makeFooter();
   // remove new lines and compress web page by using
   // 'CompressContentFacade' class
   $compressedWebPage=CompressContentFacade::stripContent
($webPage->getXHTML());
   // display compressed web page
   echo $compressedWebPage;
}
catch(Exception $e){
   echo $e->getMessage();
   exit();
}

In the above example, you can see that I first instantiated a new “WebPage” object, then generated the different sections that comprise a sample web document, and finally used the “CompressContentFacade” class to compress the respective HTTP output before sending it straight to the browser.

Do you see how applying the facade pattern with PHP 5 was much simpler that you might have thought? I bet you do!

Final thoughts

Finally, we’ve come to the end of this tutorial. In this first part of the series, I introduced the key points for how to implement the facade pattern with PHP 5 with some illustrative examples.

However, this isn’t the end of this educational journey. In the last installment, I’ll teach you how to use a facade class in conjunction with a file processing application. You won’t want to miss it!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: