1 <?php
2
3 class Kint_Objects_Closure extends KintObject
4 {
5 public function parse( & $variable )
6 {
7 if ( !$variable instanceof Closure ) return false;
8
9 $this->name = 'Closure';
10 $reflection = new ReflectionFunction( $variable );
11 $ret = array(
12 'Parameters' => array()
13 );
14 if ( $val = $reflection->getParameters() ) {
15 foreach ( $val as $parameter ) {
16
17 $ret['Parameters'][] = $parameter->name;
18 }
19
20 }
21 if ( $val = $reflection->getStaticVariables() ) {
22 $ret['Uses'] = $val;
23 }
24 if ( method_exists($reflection, 'getClousureThis') && $val = $reflection->getClosureThis() ) {
25 $ret['Uses']['$this'] = $val;
26 }
27 if ( $val = $reflection->getFileName() ) {
28 $this->value = Kint::shortenPath( $val ) . ':' . $reflection->getStartLine();
29 }
30
31 return $ret;
32 }
33
34
35 public function isDefaultValueAvailable()
36 {
37 if ( PHP_VERSION_ID === 50316 ) {
38 try {
39 $this->getDefaultValue();
40 return true;
41 } catch ( \ReflectionException $e ) {
42 return false;
43 }
44 }
45 return parent::isDefaultValueAvailable();
46 }
47 }
48