splfileinfo.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class Kint_Objects_SplFileInfo extends KintObject
  3. {
  4. public function parse( & $variable )
  5. {
  6. if ( !KINT_PHP53 || !is_object( $variable ) || !$variable instanceof SplFileInfo ) return false;
  7. $this->name = 'SplFileInfo';
  8. $this->value = $variable->getBasename();
  9. $flags = array();
  10. $perms = $variable->getPerms();
  11. if ( ( $perms & 0xC000 ) === 0xC000 ) {
  12. $type = 'File socket';
  13. $flags[] = 's';
  14. } elseif ( ( $perms & 0xA000 ) === 0xA000 ) {
  15. $type = 'File symlink';
  16. $flags[] = 'l';
  17. } elseif ( ( $perms & 0x8000 ) === 0x8000 ) {
  18. $type = 'File';
  19. $flags[] = '-';
  20. } elseif ( ( $perms & 0x6000 ) === 0x6000 ) {
  21. $type = 'Block special file';
  22. $flags[] = 'b';
  23. } elseif ( ( $perms & 0x4000 ) === 0x4000 ) {
  24. $type = 'Directory';
  25. $flags[] = 'd';
  26. } elseif ( ( $perms & 0x2000 ) === 0x2000 ) {
  27. $type = 'Character special file';
  28. $flags[] = 'c';
  29. } elseif ( ( $perms & 0x1000 ) === 0x1000 ) {
  30. $type = 'FIFO pipe file';
  31. $flags[] = 'p';
  32. } else {
  33. $type = 'Unknown file';
  34. $flags[] = 'u';
  35. }
  36. // owner
  37. $flags[] = ( ( $perms & 0x0100 ) ? 'r' : '-' );
  38. $flags[] = ( ( $perms & 0x0080 ) ? 'w' : '-' );
  39. $flags[] = ( ( $perms & 0x0040 ) ? ( ( $perms & 0x0800 ) ? 's' : 'x' ) : ( ( $perms & 0x0800 ) ? 'S' : '-' ) );
  40. // group
  41. $flags[] = ( ( $perms & 0x0020 ) ? 'r' : '-' );
  42. $flags[] = ( ( $perms & 0x0010 ) ? 'w' : '-' );
  43. $flags[] = ( ( $perms & 0x0008 ) ? ( ( $perms & 0x0400 ) ? 's' : 'x' ) : ( ( $perms & 0x0400 ) ? 'S' : '-' ) );
  44. // world
  45. $flags[] = ( ( $perms & 0x0004 ) ? 'r' : '-' );
  46. $flags[] = ( ( $perms & 0x0002 ) ? 'w' : '-' );
  47. $flags[] = ( ( $perms & 0x0001 ) ? ( ( $perms & 0x0200 ) ? 't' : 'x' ) : ( ( $perms & 0x0200 ) ? 'T' : '-' ) );
  48. $size = sprintf( '%.2fK', $variable->getSize() / 1024 );
  49. $flags = implode( $flags );
  50. $path = $variable->getRealPath();
  51. return array(
  52. 'File information' => array(
  53. 'Full path' => $path,
  54. 'Type' => $type,
  55. 'Size' => $size,
  56. 'Flags' => $flags
  57. )
  58. );
  59. }
  60. }