Exemple #1
0
 public function parse(&$var, Kint_Object &$o)
 {
     if (!$var instanceof Closure || !$o instanceof Kint_Object_Instance || !$this->parseChildren($o)) {
         return;
     }
     $o = $o->transplant(new Kint_Object_Closure());
     $o->removeRepresentation('properties');
     $closure = new ReflectionFunction($var);
     $o->filename = $closure->getFileName();
     $o->startline = $closure->getStartLine();
     foreach ($closure->getParameters() as $param) {
         $o->parameters[] = new Kint_Object_Parameter($param);
     }
     $p = new Kint_Object_Representation('Parameters');
     $p->contents =& $o->parameters;
     $o->addRepresentation($p, 0);
     $statics = array();
     if (method_exists($closure, 'getClosureThis') && ($v = $closure->getClosureThis())) {
         $statics = array('this' => $v);
     }
     if (count($statics = $statics + $closure->getStaticVariables())) {
         foreach ($statics as $name => &$static) {
             $obj = Kint_Object::blank('$' . $name);
             $obj->depth = $o->depth + 1;
             $static = $this->parser->parse($static, $obj);
             if ($static->value === null) {
                 $static->access_path = null;
             }
         }
         $r = new Kint_Object_Representation('Uses');
         $r->contents = $statics;
         $o->addRepresentation($r, 0);
     }
 }
Exemple #2
0
 public function parse(&$var, Kint_Object &$o)
 {
     if ($o->type !== 'object' || !$o instanceof Kint_Object_Instance || !$this->parseChildren($o)) {
         return;
     }
     $class = get_class($var);
     $reflection = new ReflectionClass($class);
     // Constants
     // TODO: PHP 7.1 will allow private consts
     if (!isset(self::$cache[$class])) {
         $consts = array();
         foreach ($reflection->getConstants() as $name => $val) {
             $const = Kint_Object::blank($name);
             $const->const = true;
             $const->depth = $o->depth + 1;
             $const->owner_class = $class;
             if (KINT_PHP53) {
                 $const->access_path = '\\' . $class . '::' . $const->name;
             } else {
                 $const->access_path = $class . '::' . $const->name;
             }
             $const->operator = Kint_Object::OPERATOR_STATIC;
             $const = $this->parser->parse($val, $const);
             $consts[] = $const;
         }
         self::$cache[$class] = $consts;
     }
     $statics = new Kint_Object_Representation('Static class properties', 'statics');
     $statics->contents = self::$cache[$class];
     // Statics
     foreach ($reflection->getProperties(ReflectionProperty::IS_STATIC) as $static) {
         $prop = new Kint_Object();
         $prop->name = '$' . $static->getName();
         $prop->depth = $o->depth + 1;
         $prop->static = true;
         $prop->owner_class = $static->getDeclaringClass()->name;
         $prop->operator = Kint_Object::OPERATOR_STATIC;
         $prop->access = Kint_Object::ACCESS_PUBLIC;
         if ($static->isProtected()) {
             $static->setAccessible(true);
             $prop->access = Kint_Object::ACCESS_PROTECTED;
         } elseif ($static->isPrivate()) {
             $static->setAccessible(true);
             $prop->access = Kint_Object::ACCESS_PRIVATE;
         }
         if ($this->parser->childHasPath($o, $prop)) {
             if (KINT_PHP53) {
                 $prop->access_path = '\\' . $prop->owner_class . '::' . $prop->name;
             } else {
                 $prop->access_path = $prop->owner_class . '::' . $prop->name;
             }
         }
         $val = $static->getValue();
         $prop = $this->parser->parse($val, $prop);
         $statics->contents[] = $prop;
     }
     if (empty($statics->contents)) {
         return;
     }
     usort($statics->contents, array('Kint_Parser_Plugin_ClassStatics', 'sort'));
     $o->addRepresentation($statics);
 }
Exemple #3
0
 /**
  * Dump information about variables, accepts any number of parameters, supports modifiers:.
  *
  *  clean up any output before kint and place the dump at the top of page:
  *   - Kint::dump()
  *  *****
  *  expand all nodes on display:
  *   ! Kint::dump()
  *  *****
  *  dump variables disregarding their depth:
  *   + Kint::dump()
  *  *****
  *  return output instead of displaying it:
  *
  *   @ Kint::dump()
  *  *****
  *  force output as plain text
  *   ~ Kint::dump()
  *
  * Modifiers are supported by all dump wrapper functions, including Kint::trace(). Space is optional.
  *
  * @param mixed $data
  *
  * @return void|string
  */
 public static function dump($data = null)
 {
     if (!self::$enabled_mode) {
         return '';
     }
     $stash = self::settings();
     list($names, $parameters, $modifiers, $callee, $caller, $mini_trace) = self::getCalleeInfo(defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace());
     // set mode for current run
     if (self::$enabled_mode === true) {
         self::$enabled_mode = self::$mode_default;
         if (PHP_SAPI === 'cli' && self::$cli_detection === true) {
             self::$enabled_mode = self::$mode_default_cli;
         }
     }
     if (strpos($modifiers, '~') !== false) {
         self::$enabled_mode = self::MODE_WHITESPACE;
     }
     if (!array_key_exists(self::$enabled_mode, self::$renderers)) {
         $renderer = self::$renderers[self::MODE_PLAIN];
     } else {
         $renderer = self::$renderers[self::$enabled_mode];
     }
     // process modifiers: @, +, ! and -
     if (strpos($modifiers, '-') !== false) {
         while (ob_get_level()) {
             ob_end_clean();
         }
     }
     if (strpos($modifiers, '!') !== false) {
         self::$expanded = true;
     }
     if (strpos($modifiers, '+') !== false) {
         self::$max_depth = false;
     }
     if (strpos($modifiers, '@') !== false) {
         self::$return = true;
     }
     $renderer = new $renderer($names, $parameters, $modifiers, $callee, $caller, $mini_trace);
     $output = call_user_func(array($renderer, 'preRender'));
     $parser = new Kint_Parser(self::$max_depth, empty($caller['class']) ? null : $caller['class']);
     if ($names === array(null) && func_num_args() === 1 && $data === 1) {
         // Kint::dump(1) shorthand
         $trace = Kint_Parser_Plugin_Trace::trimTrace(debug_backtrace(true));
         $lastframe = array_shift($trace);
         $tracename = $lastframe['function'] . '(1)';
         if (isset($lastframe['class'], $lastframe['type'])) {
             $tracename = $lastframe['class'] . $lastframe['type'] . $tracename;
         }
         $tracebase = Kint_Object::blank($tracename, 'debug_backtrace()');
         if (empty($trace)) {
             $output .= call_user_func(array($renderer, 'render'), $tracebase->transplant(new Kint_Object_Trace()));
         } else {
             $output .= call_user_func(array($renderer, 'render'), $parser->parse($trace, $tracebase));
         }
     } else {
         $data = func_get_args();
         if ($data === array()) {
             $output .= call_user_func(array($renderer, 'render'), new Kint_Object_Nothing());
         }
         foreach ($data as $i => $argument) {
             $output .= call_user_func(array($renderer, 'render'), $parser->parse($argument, Kint_Object::blank(isset($names[$i]) ? $names[$i] : null, isset($parameters[$i]) ? $parameters[$i] : null)));
         }
     }
     $output .= call_user_func(array($renderer, 'postRender'));
     if (self::$return) {
         self::settings($stash);
         return $output;
     }
     self::settings($stash);
     echo $output;
     return '';
 }