Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2.  
  3.     ### This section resides in the framework ###
  4.  
  5.     class Forms {
  6.         /**
  7.          * @var array Holds a list of forms.
  8.          */
  9.         protected static $forms=array();
  10.         /**
  11.          * Register form class name.
  12.          * @param string $form Form class.
  13.          */
  14.         public static function register($form){
  15.             self::$forms[]=$form;
  16.         }
  17.         /**
  18.          * Prints out some stuff about loaded forms.
  19.          */
  20.         public function all(){
  21.             echo count(self::$forms).' form(s): '.implode(', ',self::$forms);
  22.         }
  23.         /**
  24.          * Returns a list of form classes.
  25.          * Makes use of a custom function that loops through all register PHP classes and finds those that subclass a specific class.
  26.          */
  27. //3     public function forms(){
  28. //3         return get_class_grandchildren('Form');
  29. //3     }
  30.     }
  31.  
  32.     class Form {
  33.         /**
  34.          * @var integer Form ID.
  35.          */
  36.         public $id=0;
  37.         /**
  38.          * @var string Form hint, must be overriden.
  39.          */
  40.         public static $hint='Form Template';
  41.         /**
  42.          * Returns form name (optionally overriden).
  43.          * @return string The form's name.
  44.          */
  45.         public function name(){
  46.             return 'Form'.$id;
  47.         }
  48.         /**
  49.          * Returns the form's HTML code.
  50.          * @return string The HTML code.
  51.          */
  52.         public function render(){
  53.             return '';
  54.         }
  55.         /**
  56.          * This is a hypothetical PHP magic method triggered when this class has been extended.
  57.          * @param string $class The class name of the subclass that triggered this method.
  58.          */
  59. //2     public function __extended($class){
  60. //2         Forms::register($class);
  61. //2     }
  62.     }
  63.  
  64.  
  65.     ### This section resides in the framework template/plugin/3rdparty ###
  66.  
  67.     class LoginForm extends Form {
  68.         public static $hint='Login Form Template';
  69.         public function name(){
  70.             return 'Login'.$this->id;
  71.         }
  72.         public function render(){
  73.             return 'User: <input type="text" name="user"/> Pass: <input type="password" name="pass"/>';
  74.         }
  75.     }
  76. //1 Forms::register('LoginForm');
  77.  
  78.     class RegisterForm extends Form {
  79.         public static $hint='User Registration Form';
  80.         public function name(){
  81.             return 'Register'.$this->id;
  82.         }
  83.         public function render(){
  84.             return 'User: <input type="text" name="user"/> Pass: <input type="password" name="pass"/> Email: <input type="text" name="email"/>';
  85.         }
  86.     }
  87. //1 Forms::register('RegisterForm');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement