Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ### This section resides in the framework ###
- class Forms {
- /**
- * @var array Holds a list of forms.
- */
- protected static $forms=array();
- /**
- * Register form class name.
- * @param string $form Form class.
- */
- public static function register($form){
- self::$forms[]=$form;
- }
- /**
- * Prints out some stuff about loaded forms.
- */
- public function all(){
- echo count(self::$forms).' form(s): '.implode(', ',self::$forms);
- }
- /**
- * Returns a list of form classes.
- * Makes use of a custom function that loops through all register PHP classes and finds those that subclass a specific class.
- */
- //3 public function forms(){
- //3 return get_class_grandchildren('Form');
- //3 }
- }
- class Form {
- /**
- * @var integer Form ID.
- */
- public $id=0;
- /**
- * @var string Form hint, must be overriden.
- */
- public static $hint='Form Template';
- /**
- * Returns form name (optionally overriden).
- * @return string The form's name.
- */
- public function name(){
- return 'Form'.$id;
- }
- /**
- * Returns the form's HTML code.
- * @return string The HTML code.
- */
- public function render(){
- return '';
- }
- /**
- * This is a hypothetical PHP magic method triggered when this class has been extended.
- * @param string $class The class name of the subclass that triggered this method.
- */
- //2 public function __extended($class){
- //2 Forms::register($class);
- //2 }
- }
- ### This section resides in the framework template/plugin/3rdparty ###
- class LoginForm extends Form {
- public static $hint='Login Form Template';
- public function name(){
- return 'Login'.$this->id;
- }
- public function render(){
- return 'User: <input type="text" name="user"/> Pass: <input type="password" name="pass"/>';
- }
- }
- //1 Forms::register('LoginForm');
- class RegisterForm extends Form {
- public static $hint='User Registration Form';
- public function name(){
- return 'Register'.$this->id;
- }
- public function render(){
- return 'User: <input type="text" name="user"/> Pass: <input type="password" name="pass"/> Email: <input type="text" name="email"/>';
- }
- }
- //1 Forms::register('RegisterForm');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement