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(
  26.             Gobject::TYPE_STRINGGobject::TYPE_STRINGGobject::TYPE_STRING
  27.         );
  28.  
  29.         $this->set_model($this->model);
  30.         $this->createColumns(array('Key''Type''Value'));
  31.     }//protected function build()
  32.  
  33.  
  34.  
  35.     /**
  36.     *   Set the variable (and their name) to display.
  37.     *
  38.     *   @param mixed  $variable   Variable to display
  39.     *   @param string $name       Name of the variable
  40.     */
  41.     public function setVariable($variable$name '')
  42.     {
  43.         $this->buildValues($variable$name);
  44.     }//public function setVariable($variable, $name = '')
  45.  
  46.  
  47.  
  48.     /**
  49.     *   Adds all the children of the given $variable to the list
  50.     *   on the right side.
  51.     *   Arrays and objects are not added, as they appear on the
  52.     *   tree on the left.
  53.     *
  54.     *   @param mixed    $variable   The variable whose children values shall be shown
  55.     */
  56.     protected function buildValues($variable$name)
  57.     {
  58.         $this->model->clear();
  59.         switch (gettype($variable))
  60.         {
  61.             case 'object':
  62.                 if (class_exists(get_class($variable))) {
  63.                     $arKeys array_keys(get_object_vars($variable));
  64.                 else {
  65.                     $arKeys = array('error');
  66.                     $variable = null;
  67.                     $variable->error = 'Class not available in PHP';
  68.                 }
  69.                 foreach ($arKeys as $key{
  70.                     $value $variable->$key;
  71.                     $this->appendValue($key$value);
  72.                 }
  73.                 break;
  74.  
  75.             case 'array':
  76.                 $arKeys array_keys($variable);
  77.                 foreach ($arKeys as $key{
  78.                     $value $variable[$key];
  79.                     $this->appendValue($key$value);
  80.                 }
  81.                 break;
  82.  
  83.             default:
  84.                 //simple type
  85.                 $this->appendValue($name$variable);
  86.                 break;
  87.         }
  88.     }//protected function buildValues($variable)
  89.  
  90.  
  91.  
  92.     /**
  93.     *   Appends one value to the list on the right.
  94.     *   Arrays and objects will not be displayed, as they already
  95.     *   appear on the tree on the left side.
  96.     *
  97.     *   @param mixed    $key    The title for the node
  98.     *   @param mixed    $value  The value to display
  99.     */
  100.     protected function appendValue($key$value)
  101.     {
  102.         switch (gettype($value)) {
  103.             case 'object':
  104.             case 'array':
  105.                 //Don't display arrays and objects in the values list
  106.                 continue;
  107.             case 'string':
  108.                 $this->model->append(
  109.                     array(
  110.                         $key,
  111.                         'string[' strlen($value']',
  112.                         $value
  113.                     )
  114.                 );
  115.                 break;
  116.             default:
  117.                 $this->model->append(
  118.                     array(
  119.                         $key,
  120.                         gettype($value),
  121.                         $value
  122.                     )
  123.                 );
  124.                 break;
  125.         }
  126.     }//protected function appendValues($variable, $arKeys)
  127.  
  128. }//class Gtk2_VarDump_List extends Gtk2_VarDump_ColTreeView
  129. ?>

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