Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. class form_field_base {
  2. // Lots of code
  3. }
  4. class form_field_text extends form_field_base {
  5. // Lots of code
  6. }
  7. class form_field_email extends form_field_text {
  8. // Extending the text object to update validation, and set input type="email"
  9. }
  10. class form_field_file extends form_field_base {
  11. // Lots of code, for example uploading files
  12. }
  13.  
  14. class form_field_base_common {
  15. // Lots of code
  16. }
  17. class form_field_base extends form_field_base_common {
  18. // By default is empty
  19. }
  20.  
  21. class form_field_text_common extends form_field_base {
  22. // Lots of code
  23. }
  24. class form_field_text extends form_field_text_common {
  25. // ...
  26. }
  27.  
  28. class form_field_email_common extends form_field_text {
  29. // Extending the text object to update validation, and set input type="email"
  30. }
  31. class form_field_email extends form_field_email_common {
  32. // ...
  33. }
  34.  
  35. class form_field_file_common extends form_field_base {
  36. // Lots of code, for example uploading files
  37. }
  38. class form_field_file extends form_field_file_common {
  39. // ...
  40. }
  41.  
  42. A <- B <- C
  43.  
  44. A->a()
  45. B->a(), B->b()
  46. C->a(), C->b(), C->c()
  47.  
  48. A1 <- B <- C
  49.  
  50. A1->a(), A1->a1(),
  51. B->a(), B->a1(), B->b()
  52. C->a(), C->a1(), C->b(), C->c()
  53.  
  54. A1 decorates A
  55. B1 decorates B
  56. C1 decorates C
  57.  
  58. A1 <- B1 <- C1
  59.  
  60. A1->a1()
  61. B1->a1()
  62. C1->a1()
  63.  
  64. A1 hosts a reference of A
  65. B1 hosts a reference of B
  66. C1 hosts a reference of C
  67.  
  68. A1->a() ----> $this->myA->a();
  69. B1->a() ----> $this->myB->a();
  70. B1->b() ----> $this->myB->b();
  71.  
  72. A1->a1() ----> $this->a1();
  73.  
  74. A1 instead of A
  75. B1 instead of B
  76. C1 instead of C
  77.  
  78. abstract class FormComponent {
  79. public __construct(FormField $field) {
  80. $this->_field = $field;
  81. }
  82.  
  83. public html() {
  84. // Here you can choose any way to integrate the field's input HTML into
  85. // the component's HTML. You can wrap it in a label, for example.
  86. return $self->_get_html() . $self->_field->html_input();
  87. }
  88. }
  89.  
  90. $field = new form_field_email($arguments); // Whatever arguments it takes
  91.  
  92. // Here the FormComponent_Email class inherits the FormComponent class
  93. $component = new FormComponent_Email($field);
  94. $component->set_hint('Some hint'); // Set your help text here
  95. $component->set_label('Enter your email');
  96.  
  97. // You can even add an error container if you wish
  98. if ($some_email_error) {
  99. $component->set_error('Your email has an error!');
  100. }
  101.  
  102. $component_html = $component->html();
Add Comment
Please, Sign In to add comment