closure.php 1.1 KB

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