"Fossies" - the Fresh Open Source Software Archive

Member "phpMyAdmin-5.1.0-english/libraries/classes/ListAbstract.php" (24 Feb 2021, 1814 Bytes) of package /linux/www/phpMyAdmin-5.1.0-english.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ListAbstract.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.0.4-english_vs_5.1.0-english.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace PhpMyAdmin;
    6 
    7 use ArrayObject;
    8 use PhpMyAdmin\Query\Utilities;
    9 use function in_array;
   10 
   11 /**
   12  * Generic list class
   13  *
   14  * @todo add caching
   15  * @abstract
   16  */
   17 abstract class ListAbstract extends ArrayObject
   18 {
   19     /** @var mixed   empty item */
   20     protected $itemEmpty = '';
   21 
   22     /**
   23      * defines what is an empty item (0, '', false or null)
   24      *
   25      * @return mixed   an empty item
   26      */
   27     public function getEmpty()
   28     {
   29         return $this->itemEmpty;
   30     }
   31 
   32     /**
   33      * checks if the given db names exists in the current list, if there is
   34      * missing at least one item it returns false otherwise true
   35      *
   36      * @param mixed[] ...$params params
   37      *
   38      * @return bool true if all items exists, otherwise false
   39      */
   40     public function exists(...$params)
   41     {
   42         $this_elements = $this->getArrayCopy();
   43         foreach ($params as $result) {
   44             if (! in_array($result, $this_elements)) {
   45                 return false;
   46             }
   47         }
   48 
   49         return true;
   50     }
   51 
   52     /**
   53      * @return array<int, array<string, bool|string>>
   54      */
   55     public function getList(): array
   56     {
   57         $selected = $this->getDefault();
   58 
   59         $list = [];
   60         foreach ($this as $eachItem) {
   61             if (Utilities::isSystemSchema($eachItem)) {
   62                 continue;
   63             }
   64 
   65             $list[] = [
   66                 'name' => $eachItem,
   67                 'is_selected' => $selected === $eachItem,
   68             ];
   69         }
   70 
   71         return $list;
   72     }
   73 
   74     /**
   75      * returns default item
   76      *
   77      * @return string  default item
   78      */
   79     public function getDefault()
   80     {
   81         return $this->getEmpty();
   82     }
   83 
   84     /**
   85      * builds up the list
   86      *
   87      * @return void
   88      */
   89     abstract public function build();
   90 }