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

Using HTTP compression with PHP 5 - 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.

  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



In consonance with the concepts that I deployed in the section that you just read, the next step that I’m going to take will consist of defining a basic facade class. This class will be capable of applying HTTP compression to any input string, in addition to removing any eventual new line characters from it.

Having outlined the functionality of this simple facade class, please pay attention to its definition. It’s as follows:

// define 'CompressContentFacade' class
class CompressContentFacade{
   public static function stripContent($content){
// remove new lines from content
     // compress content by using GZIP algorithm
     return $gzippedContent;

Despite the remarkable simplicity of the above facade class, there are a few things worth stressing about its definition. First, notice how the class in question hides all the complexity required for removing new lines characters and compressing strings behind the interface of two different classes, “StripContent” and “GzipContent” respectively.

Second, you should realize that all of these classes are completely independent from the facade one, which means that they know nothing about the class that called them. If you recall the definition of the facade pattern, this is exactly the schema required for applying it. Now, the prior facade class should make a lot of sense to you!

Nevertheless, I must mention that the previous “CompressContentFacade” class is indeed only half of the story when it comes to implementing the facade pattern with PHP 5, since the corresponding string compressing classes that you saw before remain undefined.

To address this issue, in the following section I’m going to show you the respective signature for these two new classes, in this way completing the model dictated by the facade pattern.

Do you wish to see how these classes will be created? Jump ahead and read the next few lines.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: