Skip to content

Commit

Permalink
make the database list more magic:
Browse files Browse the repository at this point in the history
load/fetch only if really required
use SPL ArrayObject to behave like an array
  • Loading branch information
CybotTM committed May 9, 2008
1 parent 91007aa commit fa21fe3
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 138 deletions.
2 changes: 1 addition & 1 deletion db_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

// rebuild the database list because PMA_Table::moveCopy
// checks in this list if the target db exists
$GLOBALS['PMA_List_Database']->build();
$GLOBALS['pma']->databases->build();
}

if (isset($GLOBALS['add_constraints'])) {
Expand Down
2 changes: 1 addition & 1 deletion export.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function PMA_exportOutputHandler($line)
$tmp_select = '|' . $tmp_select . '|';
}
// Walk over databases
foreach ($GLOBALS['PMA_List_Database']->items as $current_db) {
foreach ($GLOBALS['pma']->databases as $current_db) {
if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
|| !isset($tmp_select)) {
if (!PMA_exportDBHeader($current_db)) {
Expand Down
82 changes: 22 additions & 60 deletions libraries/List.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,97 +11,60 @@
* @since phpMyAdmin 2.9.10
* @abstract
*/
/* abstract public */ class PMA_List
abstract class PMA_List extends ArrayObject
{
/**
* @var array the list items
* @access public
*/
var $items = array();

/**
* @var array details for list items
* @access public
*/
var $details = array();

/**
* @var bool whether we need to re-index the database list for consistency keys
* @access protected
*/
var $_need_to_reindex = false;

/**
* @var mixed empty item
*/
var $item_empty = '';
protected $item_empty = '';

/**
* returns first item from list
*
* @uses PMA_List::$items to get first item
* @uses reset() to retrive first item from PMA_List::$items array
* @return string value of first item
*/
function getFirst()
public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator")
{
return reset($this->items);
parent::__construct($array, $flags, $iterator_class);
}

/**
* returns item only if there is only one in the list
*
* @uses PMA_List::count() to decide what to return
* @uses PMA_List::getFirst() to return it
* @uses count()
* @uses reset()
* @uses PMA_List::getEmpty() to return it
* @return single item
*/
function getSingleItem()
public function getSingleItem()
{
if ($this->count() === 1) {
return $this->getFirst();
if (count($this) === 1) {
return reset($this);
}

return $this->getEmpty();
}

/**
* returns list item count
*
* @uses PMA_List::$items to count it items
* @uses count() to count items in PMA_List::$items
* @return integer PMA_List::$items count
*/
function count()
{
return count($this->items);
}

/**
* defines what is an empty item (0, '', false or null)
*
* @uses PMA_List::$item_empty as return value
* @return mixed an empty item
*/
function getEmpty()
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 reutrns false other wise true
* missing at least one item it returns false other wise true
*
* @uses PMA_List::$items to check for existence of specific item
* @uses func_get_args()
* @uses in_array() to check if given arguments exists in PMA_List::$items
* @param string $db_name,.. one or more mysql result resources
* @return boolean true if all items exists, otheriwse false
*/
function exists()
public function exists()
{
foreach (func_get_args() as $result) {
if (! in_array($result, $this->items)) {
if (! in_array($result, $this)) {
return false;
}
}
Expand All @@ -119,22 +82,22 @@ function exists()
* @param boolean $include_information_schema
* @return string HTML option tags
*/
function getHtmlOptions($selected = '', $include_information_schema = true)
public function getHtmlOptions($selected = '', $include_information_schema = true)
{
if (true === $selected) {
$selected = $this->getDefault();
}

$options = '';
foreach ($this->items as $each_db) {
if (false === $include_information_schema && 'information_schema' === $each_db) {
foreach ($this as $each_item) {
if (false === $include_information_schema && 'information_schema' === $each_item) {
continue;
}
$options .= '<option value="' . htmlspecialchars($each_db) . '"';
if ($selected === $each_db) {
$options .= '<option value="' . htmlspecialchars($each_item) . '"';
if ($selected === $each_item) {
$options .= ' selected="selected"';
}
$options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
$options .= '>' . htmlspecialchars($each_item) . '</option>' . "\n";
}

return $options;
Expand All @@ -146,16 +109,15 @@ function getHtmlOptions($selected = '', $include_information_schema = true)
* @uses PMA_List::getEmpty() as fallback
* @return string default item
*/
function getDefault()
public function getDefault()
{
return $this->getEmpty();
}

/**
* builds up the list
*
* @abstract
*/
/* abstract public */ function build() {}
abstract public function build();
}
?>
Loading

0 comments on commit fa21fe3

Please sign in to comment.