PHP
  Home arrow PHP arrow Page 3 - Handling File Data with the Facade Pat...
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

Handling File Data with the Facade Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2007-01-23

    Table of Contents:
  • Handling File Data with the Facade Pattern in PHP 5
  • Using the facade pattern to handle file data
  • Applying the facade pattern to a string processor
  • Putting all the classes to work together

  • 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


    Handling File Data with the Facade Pattern in PHP 5 - Applying the facade pattern to a string processor


    (Page 3 of 4 )

    Undoubtedly, one of the best ways to understand more clearly the logic that belongs to the facade pattern consists of defining a class that implements the referenced pattern in a friendly format. In this case, I followed this approach faithfully, and created the class below. It is named “ProcessContentFacade,” and its signature is as follows:

    // define 'ProcessContentFacade' class
    class ProcessContentFacade{
        public static function processContent($content){
          // reverse content
          $reversedContent=StringToReverse::reverseString($content);
          // uppercase content
         
    $uppercasedContent=StringToUppercase::
                                  uppercaseString($reversedContent);
         
    return $uppercasedContent;
        }
    }

    As you’ll realize, the previous facade class is capable of performing a few handy formatting tasks, like uppercasing and reversing a given input string in turn. However, the most remarkable aspect concerning the signature of this class rests on the approach followed for executing these operations. They’re performed by using two additional classes, called “StringToReverse” and “StringToUppercase” respectively.

    The corresponding definitions for these additional classes are shown below. Please take a look at them:

    // define 'StringToReverse' class
    class StringToReverse{
        // reverse string
        public static function reverseString($inputString){
          if(!$inputString){
            throw new Exception('Input string must not be empty!');
          }
          return strrev($inputString);
        }
    }
    // define 'StringToUppercase' class
    class StringToUppercase{
        // uppercase string
        public static function uppercaseString($inputString){
          if(!$inputString){
            throw new Exception('Input string must not be empty!');
          }
          return strtoupper($inputString);
        }
    }

    Here, it’s clear to see how the facade pattern is appropriately implemented: on one hand you have a specific class that hides the process for reversing and uppercasing an inputted string; on the other hand, there are two classes that are completely independent from each other, and besides, they don’t know anything about the class that called them. Is this a programmatic model of the facade pattern? Of course it is!

    Okay, I have to admit that I got caught up for a moment. But seriously, the three classes that you saw before demonstrate how easy it is to implement the facade pattern with PHP 5.

    Now that you have properly grasped the logic followed by this group of classes, it’s time to move forward. We'll see how the file processor that I built in the beginning of this article can be incorporated into one single example. In this way we'll complete the implementation of the facade pattern.

    As you can see, all the pieces of this puzzle are starting to fit together. If you want to see how this journey ends, click on the link below and read the final section of this tutorial. We’re almost done!

    More PHP Articles
    More By Alejandro Gervasio


       · In this final article of the series, another example on how to implement the facade...
     

       

    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