PHP
  Home arrow PHP arrow Page 5 - Introducing the Facade Pattern in PHP ...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Introducing the Facade Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-01-16

    Table of Contents:
  • Introducing the Facade Pattern in PHP 5
  • A basic implementation of the facade pattern
  • Using HTTP compression with PHP 5
  • Completing the facade schema
  • Seeing the facade pattern in action

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introducing the Facade Pattern in PHP 5 - Seeing the facade pattern in action


    (Page 5 of 5 )

    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!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In this first part of the series, the foundations of the facade pattern are...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT