Gtk2_VarDump
[ class tree: Gtk2_VarDump ] [ index: Gtk2_VarDump ] [ all elements ]

Source for file List.php

Documentation is available at List.php

  1. <?php
  2. require_once 'Gtk2/VarDump/ColTreeView.php';
  3.  
  4. /**
  5. *   Listview for Gtk2_VarDump
  6. *
  7. *   @author Christian Weiske <cweiske@php.net>
  8. */
  9. class Gtk2_VarDump_List extends Gtk2_VarDump_ColTreeView
  10. {
  11.     public function __construct()
  12.     {
  13.         parent::__construct();
  14.         $this->build();
  15.     }//public function __construct()
  16.  
  17.  
  18.  
  19.     /**
  20.     *   Create the GUI and set up all the things
  21.     */
  22.     protected function build()
  23.     {
  24.         //Keyname, Type (+ size), Value
  25.         $this->model = new GtkListStore(Gtk::TYPE_STRINGGtk::TYPE_STRINGGtk::TYPE_STRING);
  26.  
  27.         $this->set_model($this->model);
  28.         $this->createColumns(array('Key''Type''Value'));
  29.     }//protected function build()
  30.  
  31.  
  32.  
  33.     /**
  34.     *   Set the variable (and their name) to display.
  35.     *
  36.     *   @param mixed  $variable   Variable to display
  37.     *   @param string $name       Name of the variable
  38.     */
  39.     public function setVariable($variable$name '')
  40.     {
  41.         $this->buildValues($variable$name);
  42.     }//public function setVariable($variable, $name = '')
  43.  
  44.  
  45.  
  46.     /**
  47.     *   Adds all the children of the given $variable to the list
  48.     *   on the right side.
  49.     *   Arrays and objects are not added, as they appear on the
  50.     *   tree on the left.
  51.     *
  52.     *   @param mixed    $variable   The variable whose children values shall be shown
  53.     */
  54.     protected function buildValues($variable$name)
  55.     {
  56.         $this->model->clear();
  57.         switch (gettype($variable))
  58.         {
  59.             case 'object':
  60.                 if (class_exists(get_class($variable))) {
  61.                     $arKeys array_keys(get_object_vars($variable));
  62.                 else {
  63.                     $arKeys = array('error');
  64.                     $variable = null;
  65.                     $variable->error = 'Class not available in PHP';
  66.                 }
  67.                 foreach ($arKeys as $key{
  68.                     $value $variable->$key;
  69.                     $this->appendValue($key$value);
  70.                 }
  71.                 break;
  72.  
  73.             case 'array':
  74.                 $arKeys array_keys($variable);
  75.                 foreach ($arKeys as $key{
  76.                     $value $variable[$key];
  77.                     $this->appendValue($key$value);
  78.                 }
  79.                 break;
  80.  
  81.             default:
  82.                 //simple type
  83.                 $this->appendValue($name$variable);
  84.                 break;
  85.         }
  86.     }//protected function buildValues($variable)
  87.  
  88.  
  89.  
  90.     /**
  91.     *   Appends one value to the list on the right.
  92.     *   Arrays and objects will not be displayed, as they already
  93.     *   appear on the tree on the left side.
  94.     *
  95.     *   @param mixed    $key    The title for the node
  96.     *   @param mixed    $value  The value to display
  97.     */
  98.     protected function appendValue($key$value)
  99.     {
  100.         switch (gettype($value)) {
  101.             case 'object':
  102.             case 'array':
  103.                 //Don't display arrays and objects in the values list
  104.                 continue;
  105.             case 'string':
  106.                 $this->model->append(
  107.                     array(
  108.                         $key,
  109.                         'string[' strlen($value']',
  110.                         $value
  111.                     )
  112.                 );
  113.                 break;
  114.             default:
  115.                 $this->model->append(
  116.                     array(
  117.                         $key,
  118.                         gettype($value),
  119.                         $value
  120.                     )
  121.                 );
  122.                 break;
  123.         }
  124.     }//protected function appendValues($variable, $arKeys)
  125.  
  126. }//class Gtk2_VarDump_List extends Gtk2_VarDump_ColTreeView
  127. ?>

Documentation generated on Mon, 11 Mar 2019 14:42:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.