protected function _encodeVariable($Variable, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1) { /* if($Variable===self::UNDEFINED) { $var = array('type'=>'constant', 'constant'=>'undefined'); if($this->options['includeLanguageMeta']) { $var['lang.type'] = 'undefined'; } return $var; } else */ if (is_null($Variable)) { $var = array('type' => 'constant', 'constant' => 'null'); if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'null'; } } else { if (is_bool($Variable)) { $var = array('type' => 'constant', 'constant' => $Variable ? 'true' : 'false'); if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'boolean'; } } else { if (is_int($Variable)) { $var = array('type' => 'text', 'text' => (string) $Variable); if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'integer'; } } else { if (is_float($Variable)) { $var = array('type' => 'text', 'text' => (string) $Variable); if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'float'; } } else { if (is_object($Variable)) { $sub = $this->_encodeInstance($Variable, $ObjectDepth, $ArrayDepth, $MaxDepth); $var = array('type' => 'reference', 'reference' => $sub['value']); if (isset($sub['meta'])) { $var = Insight_Util::array_merge($var, $sub['meta']); } } else { if (is_array($Variable)) { if (isset($Variable[self::SKIP])) { unset($Variable[self::SKIP]); return $Variable; } $sub = null; // Check if we have an indexed array (list) or an associative array (map) if (Insight_Util::is_list($Variable)) { $sub = $this->_encodeArray($Variable, $ObjectDepth, $ArrayDepth, $MaxDepth); $var = array('type' => 'array', 'array' => $sub['value']); } else { if ($this->getOption('treatArrayMapAsDictionary')) { $sub = $this->_encodeAssociativeArray($Variable, $ObjectDepth, $ArrayDepth, $MaxDepth); $var = array('type' => 'dictionary', 'dictionary' => isset($sub['value']) ? $sub['value'] : false); } else { $sub = $this->_encodeAssociativeArray($Variable, $ObjectDepth, $ArrayDepth, $MaxDepth); $var = array('type' => 'map', 'map' => isset($sub['value']) ? $sub['value'] : false); } } if (isset($sub['meta'])) { $var = Insight_Util::array_merge($var, $sub['meta']); } if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'array'; } } else { if (is_resource($Variable)) { // TODO: Try and get more info about resource $var = array('type' => 'text', 'text' => (string) $Variable); if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'resource'; } } else { if (is_string($Variable)) { $var = array('type' => 'text'); // TODO: Add info about encoding if (Insight_Util::is_utf8($Variable)) { $var['text'] = $Variable; } else { $var['text'] = utf8_encode($Variable); } $maxLength = $this->getOption('maxStringLength'); $lengthNoLimit = $this->getOption('lengthNoLimit'); if ($maxLength >= 0 && strlen($var['text']) >= $maxLength && $lengthNoLimit !== true) { $var['encoder.trimmed'] = true; $var['encoder.trimmed.partial'] = true; $var['encoder.notice'] = 'Max String Length (' . $maxLength . ') ' . (strlen($var['text']) - $maxLength) . ' more'; $var['text'] = substr($var['text'], 0, $maxLength); } if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'string'; } } else { $var = array('type' => 'text', 'text' => (string) $Variable); if ($this->getOption('includeLanguageMeta')) { $var['lang.type'] = 'unknown'; } } } } } } } } } return $var; }
public function table($title, $data, $header = false) { if (is_object($data)) { // convert object to name/value table $originalData = $data; $data = array(); foreach ((array) $originalData as $name => $value) { $data[] = array($name, $value); } } else { if (is_array($data)) { if (Insight_Util::is_list($data)) { // we have a simple list // this means we have a set of rows with cells or just a list where each element should be it's own row $originalData = $data; $isSimple = false; foreach ($originalData as $value) { // if value is not an array we assume we have a list where the value should be it's own row // i.e. we will wrap each value in an array to simulate a row with one cell if (!is_array($value) || !Insight_Util::is_list($value)) { $isSimple = true; break; } } if ($isSimple) { // wrap each element in an array to simulate a row with one cell $data = array(); foreach ($originalData as $name => $value) { $data[] = array($value); } } } else { // convert associative array to name/value table $originalData = $data; $data = array(); foreach ($originalData as $name => $value) { $data[] = array($name, $value); } } } } $meta = array('renderer' => 'insight:structures/table', 'encoder.rootDepth' => 4); if (isset($this->message->meta['.expand'])) { $meta['expand'] = true; } $this->message->meta($this->_addFileLineMeta($meta))->send(array('title' => $title, 'data' => $data, 'header' => $header)); }