PHP
  Home arrow PHP arrow Page 4 - Working with CSS Styles and the Stage 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? 
Google.com  
PHP

Working with CSS Styles and the Stage Pattern in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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!



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek