You are here

public function Kint_Objects_Closure::parse in Devel 8.2

Same name and namespace in other branches
  1. 8 kint/kint/parsers/objects/closure.php \Kint_Objects_Closure::parse()

* returns false or associative array - each key represents a tab in default view, values may be anything * *

Parameters

$variable: * * @return mixed

Overrides KintObject::parse

File

kint/kint/parsers/objects/closure.php, line 5

Class

Kint_Objects_Closure

Code

public function parse(&$variable) {
  if (!$variable instanceof Closure) {
    return false;
  }
  $this->name = 'Closure';
  $reflection = new ReflectionFunction($variable);
  $ret = array(
    'Parameters' => array(),
  );
  if ($val = $reflection
    ->getParameters()) {
    foreach ($val as $parameter) {

      // todo http://php.net/manual/en/class.reflectionparameter.php
      $ret['Parameters'][] = $parameter->name;
    }
  }
  if ($val = $reflection
    ->getStaticVariables()) {
    $ret['Uses'] = $val;
  }
  if (method_exists($reflection, 'getClousureThis') && ($val = $reflection
    ->getClosureThis())) {
    $ret['Uses']['$this'] = $val;
  }
  if ($val = $reflection
    ->getFileName()) {
    $this->value = Kint::shortenPath($val) . ':' . $reflection
      ->getStartLine();
  }
  return $ret;
}