HomePHP Working with CSS Styles and the Stage Pattern in PHP 5
Working with CSS Styles and the Stage Pattern in PHP 5
The stage pattern lets you build classes that can modify their behaviors according to the variations of a given programming context. If you want to learn more about it, then you should start reading this article now! Welcome to the final installment of the series that began with "Implementing the stage pattern in PHP 5." Made up of two articles, this series walks you through the application of this useful pattern, and complements the corresponding theory with illustrative code samples.
Stepping back quickly to the preceding tutorial of the series, you'll recall that I introduced the key concepts of the stage pattern. I also provided you with some friendly hands-on examples, aimed at demonstrating, at least basically, the functionality of this rather unusual pattern.
Speaking more specifically, in that tutorial I developed a couple of straightforward PHP classes. The first one was tasked with displaying regular DIVs on a simple web page, while the second one was capable of modifying the values assigned to the "overflow" CSS property corresponding to all these DIVs. These classes demonstrated how a particular class can change its behavior in response to the modifications introduced into its context.
Obviously, the example described above is a concise implementation of the logic followed by the stage pattern, which hopefully will help you understand more easily how it this pattern works. However, to be frank, I think that the more code samples you see covering the pattern in question, the more you'll learn about it. Therefore, in this final article of the series I'm going to provide you with another practical example of how the stage pattern works.
Essentially, what I plan to demonstrate here is how this pattern can be used to build different versions of a given web document on the fly, either for display on a typical computer monitor, or for printing. There will be a target class, responsible for defining a few CSS styles used by the pertinent web document. There will also be a contextual class to determine which of these styles will be attached to the web page in question.
Now that you know the purpose of this last tutorial of the series, let's continue learning how to implement the stage pattern with PHP 5. Let's get started now!