Ejemplo n.º 1
0
 private static function _parse_array(&$variable, kintVariableData $variableData)
 {
     isset(self::$_marker) or self::$_marker = "" . uniqid();
     # naturally, $GLOBALS variable is an intertwined recursion nightmare, use black magic
     $globalsDetector = false;
     if (array_key_exists('GLOBALS', $variable) && is_array($variable['GLOBALS'])) {
         $globalsDetector = "" . uniqid();
         $variable['GLOBALS'][$globalsDetector] = true;
         if (isset($variable[$globalsDetector])) {
             unset($variable[$globalsDetector]);
             self::$_dealingWithGlobals = true;
         } else {
             unset($variable['GLOBALS'][$globalsDetector]);
             $globalsDetector = false;
         }
     }
     $variableData->type = 'array';
     $variableData->size = count($variable);
     if ($variableData->size === 0) {
         return;
     }
     if (isset($variable[self::$_marker])) {
         # recursion; todo mayhaps show from where
         if (self::$_dealingWithGlobals) {
             $variableData->value = '*RECURSION*';
         } else {
             unset($variable[self::$_marker]);
             $variableData->value = self::$_marker;
         }
         return false;
     }
     if (self::_checkDepth()) {
         $variableData->extendedValue = "*DEPTH TOO GREAT*";
         return false;
     }
     $isSequential = self::_isSequential($variable);
     $tabular = self::_isArrayTabular($variable);
     if ($tabular) {
         $firstRow = true;
         $extendedValue = '<table class="kint-report">';
         $arrayKeys = array();
         // assure no values are unreported if an extra key appears in one of the lines
         foreach ($variable as $row) {
             // todo process all keys in _isArrayTabular()
             if (!is_array($row)) {
                 $tabular = false;
                 break;
             }
             $arrayKeys = array_unique(array_merge($arrayKeys, array_keys($row)));
         }
     }
     if ($tabular) {
         $variable[self::$_marker] = true;
         foreach ($variable as $rowIndex => &$row) {
             # display strings in their full length
             self::$_placeFullStringInValue = true;
             if ($rowIndex === self::$_marker) {
                 continue;
             }
             if (isset($row[self::$_marker])) {
                 $variableData->value = "*RECURSION*";
                 return false;
             }
             $extendedValue .= '<tr>';
             $output = '<td>' . ($isSequential ? '#' . ($rowIndex + 1) : $rowIndex) . '</td>';
             if ($firstRow) {
                 $extendedValue .= '<th>&nbsp;</th>';
             }
             foreach ($arrayKeys as $key) {
                 if ($firstRow) {
                     $extendedValue .= '<th>' . self::escape($key) . '</th>';
                 }
                 if (!array_key_exists($key, $row)) {
                     $output .= '<td class="kint-empty"></td>';
                     continue;
                 }
                 $var = kintParser::factory($row[$key]);
                 if ($var->value === self::$_marker) {
                     $variableData->value = '*RECURSION*';
                     return false;
                 } elseif ($var->value === '*RECURSION*') {
                     $output .= '<td class="kint-empty">' . Kint_Decorators_Concise::decorate($var) . '</td>';
                 } else {
                     $output .= '<td>' . Kint_Decorators_Concise::decorate($var) . '</td>';
                 }
                 unset($var);
             }
             if ($firstRow) {
                 $extendedValue .= '</tr><tr>';
                 $firstRow = false;
             }
             $extendedValue .= $output . '</tr>';
         }
         self::$_placeFullStringInValue = false;
         $variableData->extendedValue = $extendedValue . '</table>';
     } else {
         $variable[self::$_marker] = true;
         $extendedValue = array();
         foreach ($variable as $key => &$val) {
             if ($key === self::$_marker) {
                 continue;
             }
             $output = kintParser::factory($val);
             if ($output->value === self::$_marker) {
                 $variableData->value = "*RECURSION*";
                 // recursion occurred on a higher level, thus $this is recursion
                 return false;
             }
             if (!$isSequential) {
                 $output->operator = '=>';
             }
             $output->name = $isSequential ? null : "'" . self::escape($key) . "'";
             $extendedValue[] = $output;
         }
         $variableData->extendedValue = $extendedValue;
     }
     if ($globalsDetector) {
         self::$_dealingWithGlobals = false;
     }
     unset($variable[self::$_marker]);
 }
Ejemplo n.º 2
0
 private static function _parse_array(&$variable, kintVariableData $variableData)
 {
     isset(self::$_marker) or self::$_marker = "" . uniqid();
     # naturally, $GLOBALS variable is an intertwined recursion nightmare, use black magic
     $globalsDetector = false;
     if (array_key_exists('GLOBALS', $variable) && is_array($variable['GLOBALS'])) {
         $globalsDetector = "" . uniqid();
         $variable['GLOBALS'][$globalsDetector] = true;
         if (isset($variable[$globalsDetector])) {
             unset($variable[$globalsDetector]);
             self::$_dealingWithGlobals = true;
         } else {
             unset($variable['GLOBALS'][$globalsDetector]);
             $globalsDetector = false;
         }
     }
     $variableData->type = 'array';
     $variableData->size = count($variable);
     if ($variableData->size === 0) {
         return;
     }
     if (isset($variable[self::$_marker])) {
         # recursion; todo mayhaps show from where
         if (self::$_dealingWithGlobals) {
             $variableData->value = '*RECURSION*';
         } else {
             unset($variable[self::$_marker]);
             $variableData->value = self::$_marker;
         }
         return false;
     }
     if (self::_checkDepth()) {
         $variableData->extendedValue = "*DEPTH TOO GREAT*";
         return false;
     }
     $isSequential = self::_isSequential($variable);
     if ($variableData->size > 1 && ($arrayKeys = self::_isArrayTabular($variable)) !== false) {
         $variable[self::$_marker] = true;
         # this must be AFTER _isArrayTabular
         $firstRow = true;
         $extendedValue = '<table class="kint-report"><thead>';
         foreach ($variable as $rowIndex => &$row) {
             # display strings in their full length
             self::$_placeFullStringInValue = true;
             if ($rowIndex === self::$_marker) {
                 continue;
             }
             if (isset($row[self::$_marker])) {
                 $variableData->value = "*RECURSION*";
                 return false;
             }
             $extendedValue .= '<tr>';
             if ($isSequential) {
                 $output = '<td>' . '#' . ($rowIndex + 1) . '</td>';
             } else {
                 $output = self::_decorateCell(kintParser::factory($rowIndex));
             }
             if ($firstRow) {
                 $extendedValue .= '<th>&nbsp;</th>';
             }
             # we iterate the known full set of keys from all rows in case some appeared at later rows,
             # as we only check the first two to assume
             foreach ($arrayKeys as $key) {
                 if ($firstRow) {
                     $extendedValue .= '<th>' . self::escape($key) . '</th>';
                 }
                 if (!array_key_exists($key, $row)) {
                     $output .= '<td class="kint-empty"></td>';
                     continue;
                 }
                 $var = kintParser::factory($row[$key]);
                 if ($var->value === self::$_marker) {
                     $variableData->value = '*RECURSION*';
                     return false;
                 } elseif ($var->value === '*RECURSION*') {
                     $output .= '<td class="kint-empty"><u>*RECURSION*</u></td>';
                 } else {
                     $output .= self::_decorateCell($var);
                 }
                 unset($var);
             }
             if ($firstRow) {
                 $extendedValue .= '</tr></thead><tr>';
                 $firstRow = false;
             }
             $extendedValue .= $output . '</tr>';
         }
         self::$_placeFullStringInValue = false;
         $variableData->extendedValue = $extendedValue . '</table>';
     } else {
         $variable[self::$_marker] = true;
         $extendedValue = array();
         foreach ($variable as $key => &$val) {
             if ($key === self::$_marker) {
                 continue;
             }
             $output = kintParser::factory($val);
             if ($output->value === self::$_marker) {
                 $variableData->value = "*RECURSION*";
                 // recursion occurred on a higher level, thus $this is recursion
                 return false;
             }
             if (!$isSequential) {
                 $output->operator = '=>';
             }
             $output->name = $isSequential ? null : "'" . $key . "'";
             $extendedValue[] = $output;
         }
         $variableData->extendedValue = $extendedValue;
     }
     if ($globalsDetector) {
         self::$_dealingWithGlobals = false;
     }
     unset($variable[self::$_marker]);
 }