* Add native property types Includes TypeHints.UnionTypeHintFormat Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Set some default values for properties Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Format and promote properties Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Remove redundant asserts Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Redundant cast Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * $tmanager->theme is never null Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Redundant variable Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Fix empty on $statementInfo bool Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Redundant casts Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Redundant issets Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * getPacked() returns nullable string Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Redundant if Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * $this->content can be null Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Simplify ThemeManager::getInstance() Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Use isset for checking if property is initialized Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Use nullable instead of uninitialized property Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * password is no longer nullable I can't verify that none of the globals ever tried to set it to null, but the variable should never be nullable. Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Update baselines Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * $same_wide_width param can be float or int Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Update Message.php Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Cast Sub_part to int Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Fix one line doc comments Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> --------- Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
133 lines
2.8 KiB
PHP
133 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* User preferences form
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpMyAdmin\Config\Forms;
|
|
|
|
use PhpMyAdmin\Config\ConfigFile;
|
|
|
|
use function array_key_exists;
|
|
use function array_keys;
|
|
use function array_merge;
|
|
|
|
class BaseFormList
|
|
{
|
|
/**
|
|
* List of all forms
|
|
*
|
|
* @var array<string, class-string<BaseForm>>
|
|
*/
|
|
protected static array $all = [];
|
|
|
|
/** @var BaseForm[] */
|
|
private array $forms = [];
|
|
|
|
/** @return string[] */
|
|
public static function getAllFormNames(): array
|
|
{
|
|
return array_keys(static::$all);
|
|
}
|
|
|
|
/** @param string $name Name */
|
|
public static function isValid(string $name): bool
|
|
{
|
|
return array_key_exists($name, static::$all);
|
|
}
|
|
|
|
/**
|
|
* @param string $name Name
|
|
*
|
|
* @psalm-return class-string<BaseForm>|null
|
|
*/
|
|
public static function get(string $name): string|null
|
|
{
|
|
if (static::isValid($name)) {
|
|
return static::$all[$name];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/** @param ConfigFile $cf Config file instance */
|
|
final public function __construct(ConfigFile $cf)
|
|
{
|
|
$this->forms = [];
|
|
foreach (static::$all as $class) {
|
|
$this->forms[] = new $class($cf);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Processes forms, returns true on successful save
|
|
*
|
|
* @param bool $allowPartialSave allows for partial form saving
|
|
* on failed validation
|
|
* @param bool $checkFormSubmit whether check for $_POST['submit_save']
|
|
*/
|
|
public function process($allowPartialSave = true, $checkFormSubmit = true): bool
|
|
{
|
|
$ret = true;
|
|
foreach ($this->forms as $form) {
|
|
$ret = $ret && $form->process($allowPartialSave, $checkFormSubmit);
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Displays errors
|
|
*
|
|
* @return string HTML for errors
|
|
*/
|
|
public function displayErrors(): string
|
|
{
|
|
$ret = '';
|
|
foreach ($this->forms as $form) {
|
|
$ret .= $form->displayErrors();
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Reverts erroneous fields to their default values
|
|
*/
|
|
public function fixErrors(): void
|
|
{
|
|
foreach ($this->forms as $form) {
|
|
$form->fixErrors();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Tells whether form validation failed
|
|
*/
|
|
public function hasErrors(): bool
|
|
{
|
|
$ret = false;
|
|
foreach ($this->forms as $form) {
|
|
$ret = $ret || $form->hasErrors();
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Returns list of fields used in the form.
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public static function getFields(): array
|
|
{
|
|
$names = [];
|
|
foreach (static::$all as $class) {
|
|
$names = array_merge($names, $class::getFields());
|
|
}
|
|
|
|
return $names;
|
|
}
|
|
}
|