PHP
  Home arrow PHP arrow Page 4 - Introducing the Facade Pattern in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 7
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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