public function __construct($var, $level, Options $options) { parent::__construct(self::TYPE_ID, $var, $level, $options); $this->inspect_custom_data = true; $this->class_name = get_class($var); $this->tostring = null; if ($this->level < $this->options->getOption('object.max_nesting_level')) { $this->is_leaf = false; $reflection_class = new \ReflectionClass($this->class_name); // class info if ($this->options->getOption('object.show_classinfo')) { $this->class_file = $reflection_class->getFileName(); if (empty($this->class_file)) { $this->class_file = 'built-in'; } $this->class_interfaces = implode(', ', $reflection_class->getInterfaceNames()); $this->class_namespace = $reflection_class->getNamespaceName(); $class_parent_obj = $reflection_class->getParentClass(); if ($class_parent_obj) { $this->class_parent = $class_parent_obj->getName(); } else { $this->class_parent = ''; } unset($class_parent_obj); $class_parent_obj = NULL; } if ($this->options->getOption('object.show_data')) { // is there a class to show the object data? $include_class = $this->getIncludeClass($this->class_name, 'object'); if (class_exists($include_class)) { $custom_dumper = new $include_class($var); $this->object_custom_data = $custom_dumper->dump($var); $this->is_custom_data = TRUE; if (is_array($this->object_custom_data)) { $this->inspect_custom_data = $custom_dumper->getInspect(); } else { $this->inspect_custom_data = FALSE; } } else { $this->object_custom_data = (array) $var; $this->is_custom_data = FALSE; $this->inspect_custom_data = TRUE; } // Custom/array-cast data & name normalization if (!empty($this->object_custom_data) && is_array($this->object_custom_data)) { foreach ($this->object_custom_data as &$c) { $c = TFactory::factory($c, $this->level, $options); } } } // Class constants if ($this->options->getOption('object.show_constants')) { $this->class_constants = $reflection_class->getConstants(); if (!empty($this->class_constants)) { foreach ($this->class_constants as &$c) { $c = TFactory::factory($c, $this->level, $options); } } } // Object properties if ($this->options->getOption('object.show_properties')) { $object_properties = $reflection_class->getProperties(); $this->object_properties = array(); if (!empty($object_properties)) { foreach ($object_properties as $property) { if ($property->isPublic()) { $property_value = $property->getValue($this->value); $this->object_properties[$property->getName()] = TFactory::factory($property_value, $this->level, $options); } } } } // Class methods if ($this->options->getOption('object.show_methods')) { $this->class_methods = array(); $class_methods = $reflection_class->getMethods(); if (!empty($class_methods)) { foreach ($class_methods as $k => $v) { $method = $reflection_class->getMethod($v->name); if ($method->getName() == '__toString') { $this->tostring = $var->__toString(); } $method_syntax = ''; if ($method->isStatic()) { $method_syntax .= 'static '; } elseif ($method->isPublic()) { $method_syntax .= 'public '; } elseif ($method->isProtected()) { $method_syntax .= 'protected '; } elseif ($method->isPrivate()) { $method_syntax .= 'private '; } $method_syntax .= $method->getName(); $method_parameters = $method->getParameters(); $method_syntax .= '('; $method_parameters_result = array(); foreach ($method_parameters as $parameter) { $parameter_result = ''; $class = $parameter->getClass(); if ($class instanceof \ReflectionClass) { $parameter_result .= $class->getName() . ' '; } if ($parameter->isOptional()) { $parameter_result .= '['; } if ($parameter->isPassedByReference()) { $parameter_result .= '&'; } $parameter_result .= '$' . $parameter->getName(); $default = NULL; if ($parameter->isDefaultValueAvailable()) { $default = $parameter->getDefaultValue(); if ($default === null) { $default = 'NULL'; } elseif (is_bool($default)) { $default = $default ? 'TRUE' : 'FALSE'; } elseif (is_string($default)) { $default = '"' . htmlentities($default, ENT_COMPAT) . '"'; } elseif (is_array($default)) { $default = 'Array'; } $parameter_result .= ' = ' . $default; } if ($parameter->isOptional()) { $parameter_result .= ']'; } $method_parameters_result[] = $parameter_result; } $method_syntax .= implode(', ', $method_parameters_result); $method_syntax .= ')'; $this->class_methods[] = $method_syntax; } sort($this->class_methods, SORT_STRING); } } } else { $this->is_leaf = TRUE; } }
/** * Reads variables and creates TType objects * @param vars variables to dump */ private function _readVars($vars) { $nodes = array(); foreach ($vars as $var) { $nodes[] = TFactory::factory($var, 0, $this->options); } return $nodes; }
public function add($var, $index = null) { $this->value[$index] = TFactory::factory($var, $this->level, $this->options); }