Version 1
[yaffs-website] / web / modules / contrib / devel / kint / kint / parsers / custom / fspath.php
1 <?php
2
3 class Kint_Parsers_FsPath extends kintParser
4 {
5         protected function _parse( & $variable )
6         {
7                 if ( !KINT_PHP53
8                         || !is_string( $variable )
9                         || strlen( $variable ) > 2048
10                         || preg_match( '[[:?<>"*|]]', $variable )
11                         || !@is_readable( $variable ) # f@#! PHP and its random warnings
12                 ) return false;
13
14                 try {
15                         $fileInfo = new SplFileInfo( $variable );
16                         $flags    = array();
17                         $perms    = $fileInfo->getPerms();
18
19                         if ( ( $perms & 0xC000 ) === 0xC000 ) {
20                                 $type    = 'File socket';
21                                 $flags[] = 's';
22                         } elseif ( ( $perms & 0xA000 ) === 0xA000 ) {
23                                 $type    = 'File symlink';
24                                 $flags[] = 'l';
25                         } elseif ( ( $perms & 0x8000 ) === 0x8000 ) {
26                                 $type    = 'File';
27                                 $flags[] = '-';
28                         } elseif ( ( $perms & 0x6000 ) === 0x6000 ) {
29                                 $type    = 'Block special file';
30                                 $flags[] = 'b';
31                         } elseif ( ( $perms & 0x4000 ) === 0x4000 ) {
32                                 $type    = 'Directory';
33                                 $flags[] = 'd';
34                         } elseif ( ( $perms & 0x2000 ) === 0x2000 ) {
35                                 $type    = 'Character special file';
36                                 $flags[] = 'c';
37                         } elseif ( ( $perms & 0x1000 ) === 0x1000 ) {
38                                 $type    = 'FIFO pipe file';
39                                 $flags[] = 'p';
40                         } else {
41                                 $type    = 'Unknown file';
42                                 $flags[] = 'u';
43                         }
44
45                         // owner
46                         $flags[] = ( ( $perms & 0x0100 ) ? 'r' : '-' );
47                         $flags[] = ( ( $perms & 0x0080 ) ? 'w' : '-' );
48                         $flags[] = ( ( $perms & 0x0040 ) ? ( ( $perms & 0x0800 ) ? 's' : 'x' ) : ( ( $perms & 0x0800 ) ? 'S' : '-' ) );
49
50                         // group
51                         $flags[] = ( ( $perms & 0x0020 ) ? 'r' : '-' );
52                         $flags[] = ( ( $perms & 0x0010 ) ? 'w' : '-' );
53                         $flags[] = ( ( $perms & 0x0008 ) ? ( ( $perms & 0x0400 ) ? 's' : 'x' ) : ( ( $perms & 0x0400 ) ? 'S' : '-' ) );
54
55                         // world
56                         $flags[] = ( ( $perms & 0x0004 ) ? 'r' : '-' );
57                         $flags[] = ( ( $perms & 0x0002 ) ? 'w' : '-' );
58                         $flags[] = ( ( $perms & 0x0001 ) ? ( ( $perms & 0x0200 ) ? 't' : 'x' ) : ( ( $perms & 0x0200 ) ? 'T' : '-' ) );
59
60                         $this->type  = $type;
61                         $this->size  = sprintf( '%.2fK', $fileInfo->getSize() / 1024 );
62                         $this->value = implode( $flags );
63
64                 } catch ( Exception $e ) {
65                         return false;
66                 }
67
68         }
69 }