PHP
  Home arrow PHP arrow Page 3 - The Singleton and Factory Patterns in PHP: Working With Singletons
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

The Singleton and Factory Patterns in PHP: Working With Singletons
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2005-11-30


    Table of Contents:
  • The Singleton and Factory Patterns in PHP: Working With Singletons
  • Working with a single object instance: making the “formElementFactory” class a Singleton
  • The previous step: defining form element classes in PHP4
  • Ending up the coding round: defining the remaining form element classes

  • 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


    The Singleton and Factory Patterns in PHP: Working With Singletons - The previous step: defining form element classes in PHP4
    ( Page 3 of 4 )

    Before working with the Singleton model of the form element factory, it’s best to define all of the form element classes, suitable for use in PHP4. Since they’re closely similar to their counterparts in PHP5, this shouldn’t present any difficulties. Here they are:

    // class textinput
    class textinput{
        var $html;
        function textinput($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
    exit();
            }
            $this->html='<input type="text" ';
            foreach($attributes as $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }
    // class password input
    class passwordinput{
        var $html;
        function passwordinput($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
    exit();
            }
            $this->html='<input type="text" ';
            foreach($attributes as
    $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }
    // class hidden input
    class hiddeninput{
        var $html;
        function textinput($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
    exit();
            }
            $this->html='<input type="hidden" ';
            foreach($attributes as $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }
    // class file input
    class fileinput{
        var $html;
        function fileinput($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
    exit();
            }
            $this->html='<input type="file" ';
            foreach($attributes as
    $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }
    // class image input
    class imageinput{
        var $html;
        function imageinput($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
    exit();
            }
            $this->html='<input type="image" ';
            foreach($attributes as
    $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }
    // class radio button
    class radiobutton{
        var $html;
        function radiobutton($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
                exit();
            }
            $this->html='<input type="radio" ';
            foreach($attributes as $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }
    // class check box
    class checkbox{
        var $html;
        function checkbox($attributes=array()){
            if(count($attributes)<1){
                trigger_error('Invalid number of
    attributes');
    exit();
            }
            $this->html='<input type="checkbox" ';
            foreach($attributes as
    $attribute=>$value){
                $this->html.=$attribute.'="'.$value.'" ';
            }
            $this->html.='/>';
        }
        function getHTML(){
            return $this->html;
        }
    }

     

    All right, let’s pause for a moment and relax. At this point, most of the form element classes has been listed, so the walk through the source code is almost finished. There are a few more classes to be defined yet, so keep reading.



     
     
    >>> 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek