Skip to content

Commit

Permalink
Merge pull request #45 from huangzhhui/Optimized
Browse files Browse the repository at this point in the history
Optimized
  • Loading branch information
huangzhhui authored Oct 6, 2022
2 parents baedfa2 + 653d6f3 commit fe51295
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 46 deletions.
8 changes: 6 additions & 2 deletions src/app/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ public function handle()
$outputBin
);
$this->liveCommand($fullCommand);
chmod($outputBin, 0755);
$this->output->info('The application build finished, saved to ' . $outputBin);
if (file_exists($outputBin)) {
$this->output->success(sprintf('The application %s is built successfully.', $outputBin));
chmod($outputBin, 0755);
} else {
$this->output->error(sprintf('The application %s is built failed.', $outputBin));
}
}

protected function buildComposerNoDevCommand(string $php, string $composer): string
Expand Down
25 changes: 12 additions & 13 deletions src/app/DownloadHandler/MicroHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Di\Annotation\Inject;
use SplFileInfo;
use ZipArchive;

class MicroHandler extends PhpHandler
{
Expand All @@ -35,22 +36,20 @@ public function handle(string $pkgName, string $version, array $options = []): ?
if (! file_exists($savePath)) {
throw new \RuntimeException('Download failed, cannot locate the PHP bin file in local.');
}
if (! $this->isBinExists('unzip')) {
throw new \RuntimeException('Download failed, unzip command not found.');
}
// Unzip the artifact file
exec('unzip -o ' . $savePath . ' -d ' . $this->runtimePath);
$this->logger->info('Unpacking zip file ' . $savePath);
$renameTo = $this->runtimePath . '/micro_php' . $version . '.sfx';
$zip = new ZipArchive();
$zip->open($savePath);
for ($i = 0; $i < $zip->numFiles; ++$i) {
$filename = $zip->getNameIndex($i);
if ($filename === 'micro.sfx') {
copy('zip://' . $savePath . '#' . $filename, $renameTo);
}
}
$zip->close();
$this->logger->info('Unpacked zip file ' . $savePath);
// ZipArchive::extractTo('runtime', $savePath);
rename($renameFrom = $this->runtimePath . '/micro.sfx', $renameTo = $this->runtimePath . '/micro_php' . $version . '.sfx');
$this->logger->info(sprintf('Renamed %s to %s', $renameFrom, $renameTo));
unlink($savePath);
if (file_exists($this->runtimePath . '/micro.sfx.dwarf')) {
unlink($this->runtimePath . '/micro.sfx.dwarf');
}
if (file_exists($this->runtimePath . '/micro.sfx.debug')) {
unlink($this->runtimePath . '/micro.sfx.debug');
}
$this->logger->info(sprintf('Deleted %s', $savePath));
return new SplFileInfo($renameTo);
} catch (GuzzleException $exception) {
Expand Down
25 changes: 12 additions & 13 deletions src/app/DownloadHandler/PhpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;
use SplFileInfo;
use ZipArchive;

class PhpHandler extends AbstractDownloadHandler
{
Expand All @@ -37,22 +38,20 @@ public function handle(string $pkgName, string $version, array $options = []): ?
if (! file_exists($savePath)) {
throw new \RuntimeException('Download failed, cannot locate the PHP bin file in local.');
}
if (! $this->isBinExists('unzip')) {
throw new \RuntimeException('Download failed, unzip command not found.');
}
// Unzip the artifact file
exec('unzip -o ' . $savePath . ' -d ' . $this->runtimePath);
$this->logger->info('Unpacking zip file ' . $savePath);
$renameTo = $this->runtimePath . '/php' . $version;
$zip = new ZipArchive();
$zip->open($savePath);
for ($i = 0; $i < $zip->numFiles; ++$i) {
$filename = $zip->getNameIndex($i);
if ($filename === 'php') {
copy('zip://' . $savePath . '#' . $filename, $renameTo);
}
}
$zip->close();
$this->logger->info('Unpacked zip file ' . $savePath);
// ZipArchive::extractTo('runtime', $savePath);
rename($renameFrom = $this->runtimePath . '/php', $renameTo = $this->runtimePath . '/php' . $version);
$this->logger->info(sprintf('Renamed %s to %s', $renameFrom, $renameTo));
unlink($savePath);
if (file_exists($this->runtimePath . '/php.dwarf')) {
unlink($this->runtimePath . '/php.dwarf');
}
if (file_exists($this->runtimePath . '/php.debug')) {
unlink($this->runtimePath . '/php.debug');
}
$this->logger->info(sprintf('Deleted %s', $savePath));
return new SplFileInfo($renameTo);
} catch (GuzzleException $exception) {
Expand Down
19 changes: 1 addition & 18 deletions src/app/DownloadHandler/PintHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Phar;
use SplFileInfo;

class PintHandler extends AbstractDownloadHandler
class PintHandler extends DefaultHandler
{
public function handle(string $pkgName, string $version, array $options = []): ?SplFileInfo
{
Expand Down Expand Up @@ -74,21 +74,4 @@ public function handle(string $pkgName, string $version, array $options = []): ?
return new SplFileInfo($savePath . $definition->getBin());
}

public function versions(string $pkgName, array $options = []): array
{
$definition = $this->getDefinition($pkgName);
if (! $definition) {
throw new \RuntimeException('The package not found');
}
if (! $definition->getRepo() && ! $definition->getComposerName()) {
throw new NotSupportVersionsException($pkgName);
}
if ($definition->getLatestFetchType() === 'github') {
return $this->fetchVersionsFromGithubRelease($definition->getRepo(), $definition->getBin());
}
if ($definition->getLatestFetchType() === 'packagist') {
return $this->fetchVersionsFromPackagist($definition->getPkgName(), $definition->getComposerName());
}
throw new BoxException('The definition of package is invalid');
}
}

0 comments on commit fe51295

Please sign in to comment.