-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved generator of GRPC proto files
- Loading branch information
1 parent
ee79cc9
commit 578702a
Showing
11 changed files
with
293 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerBridge\GRPC; | ||
|
||
use Spiral\RoadRunnerBridge\GRPC\Exception\CompileException; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CommandExecutor | ||
{ | ||
public function execute(string $command): string | ||
{ | ||
\exec( | ||
$command, | ||
$output, | ||
$exitCode | ||
); | ||
|
||
if ($exitCode !== 0) { | ||
throw new CompileException(\implode("\n", $output), $exitCode); | ||
} | ||
|
||
return \trim(\implode("\n", $output), "\n ,"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerBridge\GRPC; | ||
|
||
use Spiral\Files\FilesInterface; | ||
use Spiral\RoadRunnerBridge\Config\GRPCConfig; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ProtocCommandBuilder | ||
{ | ||
public function __construct( | ||
private readonly FilesInterface $files, | ||
private readonly GRPCConfig $config, | ||
private readonly string $protocBinaryPath | ||
) { | ||
} | ||
|
||
public function build(string $protoDir, string $tmpDir): string | ||
{ | ||
return \sprintf( | ||
'protoc %s --php_out=%s --php-grpc_out=%s%s %s 2>&1', | ||
$this->protocBinaryPath ? '--plugin=' . $this->protocBinaryPath : '', | ||
\escapeshellarg($tmpDir), | ||
\escapeshellarg($tmpDir), | ||
$this->buildDirs($protoDir), | ||
\implode(' ', \array_map('escapeshellarg', $this->getProtoFiles($protoDir))) | ||
); | ||
} | ||
|
||
/** | ||
* Include all proto files from the directory. | ||
*/ | ||
private function getProtoFiles(string $protoDir): array | ||
{ | ||
return \array_filter( | ||
$this->files->getFiles($protoDir), | ||
static fn(string $file) => \str_ends_with($file, '.proto') | ||
); | ||
} | ||
|
||
private function buildDirs(string $protoDir): string | ||
{ | ||
$dirs = \array_filter([ | ||
$this->config->getServicesBasePath(), | ||
$protoDir, | ||
]); | ||
|
||
if ($dirs === []) { | ||
return ''; | ||
} | ||
|
||
return ' -I=' . \implode(' -I=', \array_map('escapeshellarg', $dirs)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.