BaseForm.php 2.0 KB

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