Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / libraries / List.class.php
blobe44edd55ccb96ba2bae3485113d69df91fb66a3e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Generic list class
15 * @todo add caching
16 * @abstract
17 * @package PhpMyAdmin
18 * @since phpMyAdmin 2.9.10
20 abstract class PMA_List extends ArrayObject
22 /**
23 * @var mixed empty item
25 protected $item_empty = '';
27 public function __construct(
28 $array = array(), $flags = 0, $iterator_class = "ArrayIterator"
29 ) {
30 parent::__construct($array, $flags, $iterator_class);
33 /**
34 * returns item only if there is only one in the list
36 * @return single item
38 public function getSingleItem()
40 if (count($this) === 1) {
41 return reset($this);
44 return $this->getEmpty();
47 /**
48 * defines what is an empty item (0, '', false or null)
50 * @return mixed an empty item
52 public function getEmpty()
54 return $this->item_empty;
57 /**
58 * checks if the given db names exists in the current list, if there is
59 * missing at least one item it returns false otherwise true
61 * @return boolean true if all items exists, otheriwse false
63 public function exists()
65 $this_elements = $this->getArrayCopy();
66 foreach (func_get_args() as $result) {
67 if (! in_array($result, $this_elements)) {
68 return false;
72 return true;
75 /**
76 * returns HTML <option>-tags to be used inside <select></select>
78 * @param mixed $selected the selected db or true for
79 * selecting current db
80 * @param boolean $include_information_schema whether include information schema
82 * @return string HTML option tags
84 public function getHtmlOptions(
85 $selected = '', $include_information_schema = true
86 ) {
87 if (true === $selected) {
88 $selected = $this->getDefault();
91 $options = '';
92 foreach ($this as $each_item) {
93 if (false === $include_information_schema
94 && $GLOBALS['dbi']->isSystemSchema($each_item)
95 ) {
96 continue;
98 $options .= '<option value="' . htmlspecialchars($each_item) . '"';
99 if ($selected === $each_item) {
100 $options .= ' selected="selected"';
102 $options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
105 return $options;
109 * returns default item
111 * @return string default item
113 public function getDefault()
115 return $this->getEmpty();
119 * builds up the list
121 * @return void
123 abstract public function build();