PHP
  Home arrow PHP arrow Page 4 - Working with CSS Styles and the Stage ...
Dev Shed Forums 
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

Working with CSS Styles and the Stage Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-04-25

    Table of Contents:
  • Working with CSS Styles and the Stage Pattern in PHP 5
  • Building a target class
  • Defining a basic contextual class
  • Completing the implementation of the stage pattern

  • 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


    Working with CSS Styles and the Stage Pattern in PHP 5 - Completing the implementation of the stage pattern


    (Page 4 of 4 )

    Indeed, the best way to understand how the stage pattern works with this specific implementation is by creating a functional example that demonstrates how a given web document can use different CSS styles according to specific format requirements.

    In this case, the following sample pair of scripts show how an instance of the contextual "CSScontext" class is capable of modifying the behavior of a specific "WebPage" object to generate two different versions of the same web document.

    Now that I have explained how the pertinent example is going to work, please examine the corresponding source code, which looks like this: 

    // example displaying a normal web page
    try{
       // create new 'CSSContext' object 
       $cssContext=new CSSContext();
       // set CSS styles to work with a normal web page format
       $cssContext->setPageFormat('normal');
       // create new 'WebPage' object
       $webPage=new WebPage($cssContext->getCSS());
       $webPage->makeHeader();
       $webPage->makeBody();
       $webPage->makeFooter();
       // display web page using normal format
       echo $webPage->getHTML();
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    // example displaying a printer-friendly web page
    try{
       // create new 'CSSContext' object 
       $cssContext=new CSSContext();
       // set CSS styles to work with a printer-friendly web page
    format
       $cssContext->setPageFormat('print');
       $webPage=new WebPage($cssContext->getCSS());
       $webPage->makeHeader();
       $webPage->makeBody();
       $webPage->makeFooter();
       // display web page using printer-friendly format
       echo $webPage->getHTML();
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    As shown above, the stage pattern is implemented here to change the behavior of a "WebPage" object so it can display distinct versions of the same web document. As you can see in the two previous scripts, the first time the web page is rendered, a "normal" CSS style is used, while in the second case, the page in question is displayed with a "printer-friendly" format.

    At this point, I believe that the previous code samples should give you an accurate idea of how to implement the stage pattern in a concrete situation. However, as with many other design patterns, I suggest you create your own testing examples to acquire a better grounding in how it this pattern functions.

    Final thoughts

    Unfortunately, we've come to the end of this journey. In these two tutorials, I introduced the basic concepts of the stage pattern, and also showed you a couple of functional examples where it can be applied with minor hassles.

    As you hopefully learned, if you ever need to build a class that changes the way it works according to the modifications introduced into its context, the stage pattern can provide a good method for solving this issue.

    See you in the next PHP tutorial!


    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.

       · This first article of the series walks through the key concepts on implementing the...
       · Where's the advantage? How is this any better than a simple if condition that...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - 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
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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