PHP
  Home arrow PHP arrow Page 4 - 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 - Completing the facade schema


    (Page 4 of 5 )

    As you learned in the previous section, there are still two classes whose signatures weren’t shown yet. They are necessary for completing the programmatic model imposed by the facade pattern. Below I listed the respective definitions for this pair of additional classes. They are tasked with removing new line characters from a given string, and compressing the string via the GZIP algorithm.

    That being said, the signatures for the classes in question look like this:  

    // define 'StripContent' class
    class StripContent{
       // remove new lines from content
       public static function stripString($content){
         return preg_replace(array("/r/","/n/","/
    rn/"),'',$content);
      
    }
    }
    // define 'GzipContent' class
    class GzipContent{
       // compress content by using GZIP algorithm
       public static function compressString($content){
         ob_start();
         echo $content;
         $content=gzencode(ob_get_clean(),9);
         header('Content-Encoding: gzip');
         return $content;  
       }          
    }

    As you can see, each of the above classes does its business by calling a single static method. Of course, I decided to define these methods that way, thus they’re callable from outside any object context, but this condition can be easily changed to suit your personal requirements.

    Okay, at this stage hopefully you learned the logic that stands behind the facade pattern. After all, on one hand I created a facade class which hides all the complexity required for compressing content, while on the other hand there are two independent classes that know nothing about the facade. Pretty simple, right?

    However, there’s still a missing piece here concerning the implementation of the “WebPage” class that I defined in the beginning of this article. In the final section of this tutorial, I’ll show you how to integrate the previous facade class, along with the mentioned web page generator, to compress different web documents.

    This interesting example will be set up in the following section, therefore if you want to learn more about it, please click the link below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · 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 5 hosted by Hostway
    Stay green...Green IT