BaseForm.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Base class for preferences.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Config\Forms;
  9. use PhpMyAdmin\Config\ConfigFile;
  10. use PhpMyAdmin\Config\FormDisplay;
  11. /**
  12. * Base form for user preferences
  13. */
  14. abstract class BaseForm extends FormDisplay
  15. {
  16. /**
  17. * Constructor
  18. *
  19. * @param ConfigFile $cf Config file instance
  20. * @param int|null $server_id 0 if new server, validation; >= 1 if editing a server
  21. */
  22. public function __construct(ConfigFile $cf, $server_id = null)
  23. {
  24. parent::__construct($cf);
  25. foreach (static::getForms() as $form_name => $form) {
  26. $this->registerForm($form_name, $form, $server_id);
  27. }
  28. }
  29. /**
  30. * List of available forms, each form is described as an array of fields to display.
  31. * Fields MUST have their counterparts in the $cfg array.
  32. *
  33. * To define form field, use the notation below:
  34. * $forms['Form group']['Form name'] = array('Option/path');
  35. *
  36. * You can assign default values set by special button ("set value: ..."), eg.:
  37. * 'Servers/1/pmadb' => 'phpmyadmin'
  38. *
  39. * To group options, use:
  40. * ':group:' . __('group name') // just define a group
  41. * or
  42. * 'option' => ':group' // group starting from this option
  43. * End group blocks with:
  44. * ':group:end'
  45. *
  46. * @todo This should be abstract, but that does not work in PHP 5
  47. *
  48. * @return array
  49. */
  50. public static function getForms()
  51. {
  52. return array();
  53. }
  54. /**
  55. * Returns list of fields used in the form.
  56. *
  57. * @return string[]
  58. */
  59. public static function getFields()
  60. {
  61. $names = [];
  62. foreach (static::getForms() as $form) {
  63. foreach ($form as $k => $v) {
  64. $names[] = is_int($k) ? $v : $k;
  65. }
  66. }
  67. return $names;
  68. }
  69. /**
  70. * Returns name of the form
  71. *
  72. * @todo This should be abstract, but that does not work in PHP 5
  73. *
  74. * @return string
  75. */
  76. public static function getName()
  77. {
  78. return '';
  79. }
  80. }