@@ -72,6 +72,56 @@ public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, S
7272 return $ a ;
7373 }
7474
75+ public static function castFileInfo (\SplFileInfo $ c , array $ a , Stub $ stub , $ isNested )
76+ {
77+ static $ map = array (
78+ 'path ' => 'getPath ' ,
79+ 'filename ' => 'getFilename ' ,
80+ 'basename ' => 'getBasename ' ,
81+ 'pathname ' => 'getPathname ' ,
82+ 'extension ' => 'getExtension ' ,
83+ 'realPath ' => 'getRealPath ' ,
84+ 'aTime ' => 'getATime ' ,
85+ 'mTime ' => 'getMTime ' ,
86+ 'cTime ' => 'getCTime ' ,
87+ 'inode ' => 'getInode ' ,
88+ 'size ' => 'getSize ' ,
89+ 'perms ' => 'getPerms ' ,
90+ 'owner ' => 'getOwner ' ,
91+ 'group ' => 'getGroup ' ,
92+ 'type ' => 'getType ' ,
93+ 'writable ' => 'isWritable ' ,
94+ 'readable ' => 'isReadable ' ,
95+ 'executable ' => 'isExecutable ' ,
96+ 'file ' => 'isFile ' ,
97+ 'dir ' => 'isDir ' ,
98+ 'link ' => 'isLink ' ,
99+ 'linkTarget ' => 'getLinkTarget ' ,
100+ );
101+
102+ $ prefix = Caster::PREFIX_VIRTUAL ;
103+
104+ foreach ($ map as $ key => $ accessor ) {
105+ try {
106+ $ a [$ prefix .$ key ] = $ c ->$ accessor ();
107+ } catch (\Exception $ e ) {
108+ }
109+ }
110+
111+ if (isset ($ a [$ prefix .'perms ' ])) {
112+ $ a [$ prefix .'perms ' ] = new ConstStub (sprintf ('0%o ' , $ a [$ prefix .'perms ' ]), $ a [$ prefix .'perms ' ]);
113+ }
114+
115+ static $ mapDate = array ('aTime ' , 'mTime ' , 'cTime ' );
116+ foreach ($ mapDate as $ key ) {
117+ if (isset ($ a [$ prefix .$ key ])) {
118+ $ a [$ prefix .$ key ] = new ConstStub (date ('Y-m-d H:i:s ' , $ a [$ prefix .$ key ]), $ a [$ prefix .$ key ]);
119+ }
120+ }
121+
122+ return $ a ;
123+ }
124+
75125 public static function castFixedArray (\SplFixedArray $ c , array $ a , Stub $ stub , $ isNested )
76126 {
77127 $ a += array (
0 commit comments