1616use GuzzleHttp \Exception \GuzzleException ;
1717use Hyperf \Di \Annotation \Inject ;
1818use SplFileInfo ;
19+ use ZipArchive ;
1920
2021class MicroHandler extends PhpHandler
2122{
@@ -35,22 +36,20 @@ public function handle(string $pkgName, string $version, array $options = []): ?
3536 if (! file_exists ($ savePath )) {
3637 throw new \RuntimeException ('Download failed, cannot locate the PHP bin file in local. ' );
3738 }
38- if (! $ this ->isBinExists ('unzip ' )) {
39- throw new \RuntimeException ('Download failed, unzip command not found. ' );
40- }
4139 // Unzip the artifact file
42- exec ('unzip -o ' . $ savePath . ' -d ' . $ this ->runtimePath );
40+ $ this ->logger ->info ('Unpacking zip file ' . $ savePath );
41+ $ renameTo = $ this ->runtimePath . '/micro_php ' . $ version . '.sfx ' ;
42+ $ zip = new ZipArchive ();
43+ $ zip ->open ($ savePath );
44+ for ($ i = 0 ; $ i < $ zip ->numFiles ; ++$ i ) {
45+ $ filename = $ zip ->getNameIndex ($ i );
46+ if ($ filename === 'micro.sfx ' ) {
47+ copy ('zip:// ' . $ savePath . '# ' . $ filename , $ renameTo );
48+ }
49+ }
50+ $ zip ->close ();
4351 $ this ->logger ->info ('Unpacked zip file ' . $ savePath );
44- // ZipArchive::extractTo('runtime', $savePath);
45- rename ($ renameFrom = $ this ->runtimePath . '/micro.sfx ' , $ renameTo = $ this ->runtimePath . '/micro_php ' . $ version . '.sfx ' );
46- $ this ->logger ->info (sprintf ('Renamed %s to %s ' , $ renameFrom , $ renameTo ));
4752 unlink ($ savePath );
48- if (file_exists ($ this ->runtimePath . '/micro.sfx.dwarf ' )) {
49- unlink ($ this ->runtimePath . '/micro.sfx.dwarf ' );
50- }
51- if (file_exists ($ this ->runtimePath . '/micro.sfx.debug ' )) {
52- unlink ($ this ->runtimePath . '/micro.sfx.debug ' );
53- }
5453 $ this ->logger ->info (sprintf ('Deleted %s ' , $ savePath ));
5554 return new SplFileInfo ($ renameTo );
5655 } catch (GuzzleException $ exception ) {
0 commit comments