-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] switch to symfony cli for managing server
- Loading branch information
Showing
6 changed files
with
72 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,13 @@ jobs: | |
name: phpmyadmin.phar | ||
path: . | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/[email protected] | ||
with: | ||
php-version: 7.4 | ||
coverage: none | ||
tools: symfony | ||
|
||
- name: Test init/run | ||
run: | | ||
mv phpmyadmin.phar phpmyadmin | ||
|
@@ -82,7 +89,7 @@ jobs: | |
./phpmyadmin | ||
./phpmyadmin status | ||
sleep 2 | ||
curl -I http://127.0.0.1:8888 | ||
curl -I http://127.0.0.1:8000 | ||
- name: Test self-update/rollback | ||
if: github.event_name != 'release' | ||
|
@@ -100,6 +107,7 @@ jobs: | |
- cs-check | ||
- composer-validate | ||
- test-phar | ||
- sca | ||
if: github.event_name == 'release' | ||
steps: | ||
- uses: actions/download-artifact@v1 | ||
|
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 |
---|---|---|
|
@@ -2,50 +2,73 @@ | |
|
||
namespace Zenstruck\PMA\Server\Command; | ||
|
||
use Symfony\Bundle\WebServerBundle\WebServerConfig; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\ExecutableFinder; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
abstract class BaseCommand extends Command | ||
{ | ||
protected function webserverConfig(): WebServerConfig | ||
final protected function isRunning(OutputInterface $output): bool | ||
{ | ||
if (!\file_exists($address = $this->addressFile()) || !\file_exists($router = $this->routerFile())) { | ||
throw new \RuntimeException('phpMyAdmin not initialized. Run "phpmyadmin init".'); | ||
} | ||
$process = $this->executeSymfonyCommand(['server:status'], $output); | ||
|
||
return new WebServerConfig($this->documentRoot(), 'dev', \file_get_contents($address), $router); // @phpstan-ignore-line | ||
return !\str_contains($process->getOutput(), 'Not Running'); | ||
} | ||
|
||
protected function folderName(): string | ||
/** | ||
* @param string[] $parameters | ||
*/ | ||
final protected function executeProcess(array $parameters, string $workingDir, OutputInterface $output): Process | ||
{ | ||
return 'phpmyadmin-server'; | ||
} | ||
$process = (new Process($parameters, $workingDir)) | ||
->setTimeout(null) | ||
; | ||
|
||
protected function organizationDir(): string | ||
{ | ||
return "{$_SERVER['HOME']}/.config/zenstruck"; | ||
$process->run(function($type, $buffer) use ($output) { | ||
if ($output->isVerbose()) { | ||
$output->writeln($buffer); | ||
} | ||
}); | ||
|
||
if (!$process->isSuccessful()) { | ||
throw new \RuntimeException($process->getErrorOutput()); | ||
} | ||
|
||
return $process; | ||
} | ||
|
||
protected function documentRoot(): string | ||
/** | ||
* @param string[] $parameters | ||
*/ | ||
final protected function executeSymfonyCommand(array $parameters, OutputInterface $output): Process | ||
{ | ||
return "{$this->organizationDir()}/{$this->folderName()}"; | ||
if (!\is_dir($this->documentRoot())) { | ||
throw new \RuntimeException('phpMyAdmin not initialized. Run "phpmyadmin init".'); | ||
} | ||
|
||
if (!$symfony = (new ExecutableFinder())->find('symfony')) { | ||
throw new \RuntimeException('Symfony CLI is required: https://symfony.com/download#step-1-install-symfony-cli'); | ||
} | ||
|
||
return $this->executeProcess(\array_merge([$symfony], $parameters), $this->documentRoot(), $output); | ||
} | ||
|
||
protected function addressFile(): string | ||
final protected function folderName(): string | ||
{ | ||
return "{$this->documentRoot()}/.address"; | ||
return 'phpmyadmin-server'; | ||
} | ||
|
||
protected function routerFile(): string | ||
final protected function organizationDir(): string | ||
{ | ||
return "{$this->documentRoot()}/.router.php"; | ||
return "{$_SERVER['HOME']}/.config/zenstruck"; | ||
} | ||
|
||
protected function pidFile(): string | ||
final protected function documentRoot(): string | ||
{ | ||
return $this->documentRoot().'/.pid'; | ||
return "{$this->organizationDir()}/{$this->folderName()}"; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Process\ExecutableFinder; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
|
@@ -21,7 +21,6 @@ protected function configure(): void | |
->setName('init') | ||
->setDescription('Initialize phpMyAdmin') | ||
->addArgument('version', InputArgument::OPTIONAL, 'phpMyAdmin version (blank for latest)') | ||
->addOption('address', null, InputOption::VALUE_REQUIRED, 'URL Address', '127.0.0.1:8888') | ||
->addOption('host', null, InputOption::VALUE_REQUIRED, 'MySQL Host', 'localhost') | ||
->addOption('port', null, InputOption::VALUE_REQUIRED, 'MySQL Port', '3306') | ||
->addOption('user', null, InputOption::VALUE_REQUIRED, 'MySQL User', 'root') | ||
|
@@ -34,7 +33,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$io = new SymfonyStyle($input, $output); | ||
|
||
$version = $input->getArgument('version'); | ||
$address = $input->getOption('address'); | ||
$mysqlHost = $input->getOption('host'); | ||
$mysqlPort = $input->getOption('port'); | ||
$mysqlUser = $input->getOption('user'); | ||
|
@@ -55,20 +53,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$fs->mkdir($orgDir); | ||
} | ||
|
||
$process = (new Process(['composer', 'create-project', $package, $this->folderName()], $orgDir)) | ||
->setTimeout(null) | ||
; | ||
|
||
$process->run(function($type, $buffer) use ($io) { | ||
if ($io->isVerbose()) { | ||
$io->writeln($buffer); | ||
} | ||
}); | ||
|
||
if (!$process->isSuccessful()) { | ||
throw new \RuntimeException($process->getErrorOutput()); | ||
if (!$composer = (new ExecutableFinder())->find('composer')) { | ||
throw new \RuntimeException('Composer is required: https://symfony.com/download#step-1-install-symfony-cli'); | ||
} | ||
|
||
$this->executeProcess([$composer, 'create-project', $package, $this->folderName()], $orgDir, $io); | ||
|
||
$io->comment('Generating config.inc.php'); | ||
$config = \file_get_contents(__DIR__.'/../resources/config.inc.template'); | ||
\file_put_contents($this->documentRoot().'/config.inc.php', \strtr($config, [ // @phpstan-ignore-line | ||
|
@@ -78,14 +68,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
'%%mysql_password%%' => $mysqlPass, | ||
])); | ||
|
||
$io->comment('Writing address file...'); | ||
\file_put_contents($this->addressFile(), $address); | ||
|
||
$io->comment('Writing router file...'); | ||
\file_put_contents( | ||
$this->routerFile(), | ||
\file_get_contents(__DIR__.'/../vendor/symfony/web-server-bundle/Resources/router.php') | ||
); | ||
$io->comment('Attaching Proxy Domain...'); | ||
$this->executeSymfonyCommand(['proxy:domain:attach', 'phpmyadmin'], $io); | ||
|
||
$io->success('Initialized phpMyAdmin, run "phpmyadmin" to start web server.'); | ||
|
||
|
@@ -99,7 +83,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi | |
|
||
$input->setArgument('version', $io->ask($definition->getArgument('version')->getDescription())); | ||
|
||
foreach (['address', 'host', 'port', 'user'] as $option) { | ||
foreach (['host', 'port', 'user'] as $option) { | ||
$input->setOption($option, $io->ask( | ||
$definition->getOption($option)->getDescription(), | ||
$definition->getOption($option)->getDefault() // @phpstan-ignore-line | ||
|
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