BaseForm.php 2.1 KB

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