55
66class JavaArchive
77{
8+ const MANIFEST_FILE_NAME = 'META-INF/MANIFEST.MF ' ;
9+
810 private $ manifestData = [];
911 private $ jarFile ;
1012 private $ expandedHArchive ;
1113 private $ files = [];
14+ private $ classes = [];
1215
1316 public function __construct (string $ jarFile )
1417 {
@@ -21,21 +24,38 @@ public function __construct(string $jarFile)
2124 if ($ name [strlen ($ name ) - 1 ] === '/ ' ) {
2225 continue ;
2326 }
24- $ this ->files [$ archive -> getNameIndex ( $ i )] = $ archive ->getFromIndex ($ i );
27+ $ this ->files [preg_replace ( ' /\.class$/ ' , '' , $ name )] = $ archive ->getFromIndex ($ i );
2528 }
2629
27- if (!isset ($ this ->files [' META-INF/MANIFEST.MF ' ])) {
30+ if (!isset ($ this ->files [static :: MANIFEST_FILE_NAME ])) {
2831 throw new FileNotFoundException ('Failed to load Manifest.mf ' );
2932 }
3033
31- foreach (explode ("\n" , $ this ->files [' META-INF/MANIFEST.MF ' ]) as $ attribute ) {
34+ foreach (explode ("\n" , $ this ->files [static :: MANIFEST_FILE_NAME ]) as $ attribute ) {
3235 $ attribute = str_replace (["\r" , "\n" ], '' , $ attribute );
3336 if (empty ($ attribute )) {
3437 continue ;
3538 }
3639 [$ name , $ value ] = explode (': ' , $ attribute );
3740 $ this ->manifestData [strtolower ($ name )] = trim ($ value );
3841 }
42+
43+ $ this ->files = array_filter (
44+ $ this ->files ,
45+ function ($ fileName ) {
46+ return $ fileName !== static ::MANIFEST_FILE_NAME ;
47+ },
48+ ARRAY_FILTER_USE_KEY
49+ );
50+
51+ foreach ($ this ->files as $ className => $ code ) {
52+ $ this ->classes [$ className ] = new JavaClass (new JavaClassInlineFileReader (
53+ $ className ,
54+ $ code
55+ ));
56+ }
57+
58+ var_dump ($ this ->classes );
3959 }
4060
4161 public function __debugInfo ()
0 commit comments