Skip to content

Commit fe51295

Browse files
authored
Merge pull request #45 from huangzhhui/Optimized
Optimized
2 parents baedfa2 + 653d6f3 commit fe51295

4 files changed

Lines changed: 31 additions & 46 deletions

File tree

src/app/Command/BuildCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ public function handle()
6464
$outputBin
6565
);
6666
$this->liveCommand($fullCommand);
67-
chmod($outputBin, 0755);
68-
$this->output->info('The application build finished, saved to ' . $outputBin);
67+
if (file_exists($outputBin)) {
68+
$this->output->success(sprintf('The application %s is built successfully.', $outputBin));
69+
chmod($outputBin, 0755);
70+
} else {
71+
$this->output->error(sprintf('The application %s is built failed.', $outputBin));
72+
}
6973
}
7074

7175
protected function buildComposerNoDevCommand(string $php, string $composer): string

src/app/DownloadHandler/MicroHandler.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use GuzzleHttp\Exception\GuzzleException;
1717
use Hyperf\Di\Annotation\Inject;
1818
use SplFileInfo;
19+
use ZipArchive;
1920

2021
class 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) {

src/app/DownloadHandler/PhpHandler.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Hyperf\Di\Annotation\Inject;
1919
use Psr\Http\Message\ResponseInterface;
2020
use SplFileInfo;
21+
use ZipArchive;
2122

2223
class PhpHandler extends AbstractDownloadHandler
2324
{
@@ -37,22 +38,20 @@ public function handle(string $pkgName, string $version, array $options = []): ?
3738
if (! file_exists($savePath)) {
3839
throw new \RuntimeException('Download failed, cannot locate the PHP bin file in local.');
3940
}
40-
if (! $this->isBinExists('unzip')) {
41-
throw new \RuntimeException('Download failed, unzip command not found.');
42-
}
4341
// Unzip the artifact file
44-
exec('unzip -o ' . $savePath . ' -d ' . $this->runtimePath);
42+
$this->logger->info('Unpacking zip file ' . $savePath);
43+
$renameTo = $this->runtimePath . '/php' . $version;
44+
$zip = new ZipArchive();
45+
$zip->open($savePath);
46+
for ($i = 0; $i < $zip->numFiles; ++$i) {
47+
$filename = $zip->getNameIndex($i);
48+
if ($filename === 'php') {
49+
copy('zip://' . $savePath . '#' . $filename, $renameTo);
50+
}
51+
}
52+
$zip->close();
4553
$this->logger->info('Unpacked zip file ' . $savePath);
46-
// ZipArchive::extractTo('runtime', $savePath);
47-
rename($renameFrom = $this->runtimePath . '/php', $renameTo = $this->runtimePath . '/php' . $version);
48-
$this->logger->info(sprintf('Renamed %s to %s', $renameFrom, $renameTo));
4954
unlink($savePath);
50-
if (file_exists($this->runtimePath . '/php.dwarf')) {
51-
unlink($this->runtimePath . '/php.dwarf');
52-
}
53-
if (file_exists($this->runtimePath . '/php.debug')) {
54-
unlink($this->runtimePath . '/php.debug');
55-
}
5655
$this->logger->info(sprintf('Deleted %s', $savePath));
5756
return new SplFileInfo($renameTo);
5857
} catch (GuzzleException $exception) {

src/app/DownloadHandler/PintHandler.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Phar;
1717
use SplFileInfo;
1818

19-
class PintHandler extends AbstractDownloadHandler
19+
class PintHandler extends DefaultHandler
2020
{
2121
public function handle(string $pkgName, string $version, array $options = []): ?SplFileInfo
2222
{
@@ -74,21 +74,4 @@ public function handle(string $pkgName, string $version, array $options = []): ?
7474
return new SplFileInfo($savePath . $definition->getBin());
7575
}
7676

77-
public function versions(string $pkgName, array $options = []): array
78-
{
79-
$definition = $this->getDefinition($pkgName);
80-
if (! $definition) {
81-
throw new \RuntimeException('The package not found');
82-
}
83-
if (! $definition->getRepo() && ! $definition->getComposerName()) {
84-
throw new NotSupportVersionsException($pkgName);
85-
}
86-
if ($definition->getLatestFetchType() === 'github') {
87-
return $this->fetchVersionsFromGithubRelease($definition->getRepo(), $definition->getBin());
88-
}
89-
if ($definition->getLatestFetchType() === 'packagist') {
90-
return $this->fetchVersionsFromPackagist($definition->getPkgName(), $definition->getComposerName());
91-
}
92-
throw new BoxException('The definition of package is invalid');
93-
}
9477
}

0 commit comments

Comments
 (0)