Skip to content

Commit

Permalink
Optimize php call proxy command, and add php-cs-fixer proxy command
Browse files Browse the repository at this point in the history
Signed-off-by: huangzhhui <[email protected]>
  • Loading branch information
huangzhhui committed Jun 25, 2022
1 parent 52b489e commit ccc6c7f
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 46 deletions.
43 changes: 43 additions & 0 deletions src/app/Command/AbstractPhpCallProxyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Command;

use Hyperf\Utils\Str;

abstract class AbstractPhpCallProxyCommand extends AbstractCommand
{
protected string $proxyCommand;

protected string $proxyBin;

public function configure()
{
$this->setDescription(sprintf('The proxy command of `php %s`.', $this->proxyCommand));
$this->setName($this->proxyCommand);
$this->ignoreValidationErrors();
}

public function handle()
{
$bin = $this->buildBinCommand();
$command = Str::replaceFirst($this->proxyCommand . ' ', '', (string) $this->input);
$fullCommand = sprintf('%s %s', $bin, $command);
var_dump($fullCommand);
$this->liveCommand($fullCommand);
}

protected function buildBinCommand(): string
{
$path = $this->getRuntimePath();
return $path . '/php' . $this->getCurrentPhpVersion() . ' ' . $path . '/' . $this->proxyBin;
}
}
46 changes: 0 additions & 46 deletions src/app/Command/ComposerCommand.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/app/Command/ComposerProxyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Command;

use Hyperf\Command\Annotation\Command;

#[Command]
class ComposerProxyCommand extends AbstractPhpCallProxyCommand
{
protected string $proxyCommand = 'composer';

protected string $proxyBin = 'composer.phar';
}
22 changes: 22 additions & 0 deletions src/app/Command/PhpCsFixerProxyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Command;

use Hyperf\Command\Annotation\Command;

#[Command]
class PhpCsFixerProxyCommand extends AbstractPhpCallProxyCommand
{
protected string $proxyCommand = 'php-cs-fixer';

protected string $proxyBin = 'php-cs-fixer.phar';
}
13 changes: 13 additions & 0 deletions src/app/DownloadHandler/DefaultHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@

class DefaultHandler extends AbstractDownloadHandler
{
protected array $definitions = [
'php-cs-fixer' => [
'repo' => 'FriendsOfPHP/PHP-CS-Fixer',
'bin' => 'php-cs-fixer.phar',
],
];

public function handle(string $repo, string $version, array $options = []): ?SplFileInfo
{
if (! isset($this->definitions[$repo])) {
throw new \RuntimeException('The package not found');
}
$definition = $this->definitions[$repo];
$url = $this->fetchDownloadUrlFromGithubRelease($definition['bin'], $definition['repo'], $version);
return $this->download($url, $this->runtimePath . '/', 0755);
}
}

0 comments on commit ccc6c7f

Please sign in to comment.