phpmyadmin/libraries/classes/ListAbstract.php
Maurício Meneghini Fauth 6584b01824 Use short versions of scalar types in PHP docs
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2020-01-23 12:20:04 -03:00

104 lines
2.5 KiB
PHP

<?php
/**
* hold the ListAbstract base class
*/
declare(strict_types=1);
namespace PhpMyAdmin;
use ArrayObject;
use function htmlspecialchars;
use function in_array;
/**
* Generic list class
*
* @todo add caching
* @abstract
*/
abstract class ListAbstract extends ArrayObject
{
/** @var mixed empty item */
protected $item_empty = '';
/**
* defines what is an empty item (0, '', false or null)
*
* @return mixed an empty item
*/
public function getEmpty()
{
return $this->item_empty;
}
/**
* checks if the given db names exists in the current list, if there is
* missing at least one item it returns false otherwise true
*
* @param mixed[] ...$params params
*
* @return bool true if all items exists, otherwise false
*/
public function exists(...$params)
{
$this_elements = $this->getArrayCopy();
foreach ($params as $result) {
if (! in_array($result, $this_elements)) {
return false;
}
}
return true;
}
/**
* returns HTML <option>-tags to be used inside <select></select>
*
* @param string|true $selected the selected db or true for
* selecting current db
* @param bool $include_information_schema whether include information schema
*
* @return string HTML option tags
*/
public function getHtmlOptions(
$selected = '',
$include_information_schema = true
) {
if ($selected === true) {
$selected = $this->getDefault();
}
$options = '';
foreach ($this as $each_item) {
if ($include_information_schema === false
&& $GLOBALS['dbi']->isSystemSchema($each_item)
) {
continue;
}
$options .= '<option value="' . htmlspecialchars($each_item) . '"';
if ($selected === $each_item) {
$options .= ' selected="selected"';
}
$options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
}
return $options;
}
/**
* returns default item
*
* @return string default item
*/
public function getDefault()
{
return $this->getEmpty();
}
/**
* builds up the list
*
* @return void
*/
abstract public function build();
}