Skip to content

Commit

Permalink
[minor] adjust deps, cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Sep 20, 2021
1 parent 3b3ad82 commit d833fae
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
},
"bin": ["bin/phpmyadmin"],
"require": {
"symfony/web-server-bundle": "^3.3|^4.0",
"symfony/filesystem": "^3.3|^4.0|^5.0"
"php": ">=7.2",
"symfony/web-server-bundle": "^4.4",
"symfony/filesystem": "^5.3",
"symfony/console": "^5.3"
},
"require-dev": {
"laravel-zero/phar-updater": "^1.1.1"
Expand Down
16 changes: 8 additions & 8 deletions src/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
*/
abstract class BaseCommand extends Command
{
protected function getFolderName()
protected function folderName(): string
{
return 'phpmyadmin-server';
}

protected function getOrganizationDir()
protected function organizationDir(): string
{
return "{$_SERVER['HOME']}/.config/zenstruck";
}

protected function getDocumentRoot()
protected function documentRoot(): string
{
return "{$this->getOrganizationDir()}/{$this->getFolderName()}";
return "{$this->organizationDir()}/{$this->folderName()}";
}

protected function getAddressFile()
protected function addressFile(): string
{
return "{$this->getDocumentRoot()}/.address";
return "{$this->documentRoot()}/.address";
}

protected function getRouterFile()
protected function routerFile(): string
{
return "{$this->getDocumentRoot()}/.router.php";
return "{$this->documentRoot()}/.router.php";
}
}
20 changes: 10 additions & 10 deletions src/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
final class InitCommand extends BaseCommand
{
protected function configure()
protected function configure(): void
{
$this
->setName('init')
Expand All @@ -29,7 +29,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

Expand All @@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mysqlPass = $input->getOption('password');
$fs = new Filesystem();

$fs->remove($this->getDocumentRoot());
$fs->remove($this->documentRoot());

$package = 'phpmyadmin/phpmyadmin';

Expand All @@ -51,11 +51,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$io->comment(\sprintf('Downloading phpMyAdmin <info>%s</info>...', $version ?: 'latest'));

if (!$fs->exists($orgDir = $this->getOrganizationDir())) {
if (!$fs->exists($orgDir = $this->organizationDir())) {
$fs->mkdir($orgDir);
}

$process = (new Process(['composer', 'create-project', $package, $this->getFolderName()], $orgDir))
$process = (new Process(['composer', 'create-project', $package, $this->folderName()], $orgDir))
->setTimeout(null)
;

Expand All @@ -71,28 +71,28 @@ protected function execute(InputInterface $input, OutputInterface $output)

$io->comment('Generating config.inc.php');
$config = \file_get_contents(__DIR__.'/../resources/config.inc.template');
\file_put_contents($this->getDocumentRoot().'/config.inc.php', \strtr($config, [
\file_put_contents($this->documentRoot().'/config.inc.php', \strtr($config, [
'%%mysql_host%%' => $mysqlHost,
'%%mysql_port%%' => $mysqlPort,
'%%mysql_user%%' => $mysqlUser,
'%%mysql_password%%' => $mysqlPass,
]));

$io->comment('Writing address file...');
\file_put_contents($this->getAddressFile(), $address);
\file_put_contents($this->addressFile(), $address);

$io->comment('Writing router file...');
\file_put_contents(
$this->getRouterFile(),
$this->routerFile(),
\file_get_contents(__DIR__.'/../vendor/symfony/web-server-bundle/Resources/router.php')
);

$io->success('Initialized phpMyAdmin, run "phpmyadmin" to start web server.');

return 0;
return self::SUCCESS;
}

protected function interact(InputInterface $input, OutputInterface $output)
protected function interact(InputInterface $input, OutputInterface $output): void
{
$io = new SymfonyStyle($input, $output);
$definition = $this->getDefinition();
Expand Down
23 changes: 11 additions & 12 deletions src/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,47 @@
*/
final class RunCommand extends BaseCommand
{
protected function configure()
protected function configure(): void
{
$this
->setName('run')
->setDescription('Starts/Stops the phpMyAdmin web server')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

if (!\file_exists($address = $this->getAddressFile()) || !\file_exists($router = $this->getRouterFile())) {
var_dump($address, $router);
if (!\file_exists($address = $this->addressFile()) || !\file_exists($router = $this->routerFile())) {
throw new \RuntimeException('phpMyAdmin not initialized. Run "phpmyadmin init".');
}

$server = new WebServer();

if ($server->isRunning($this->getPidFile())) {
$server->stop($this->getPidFile());
if ($server->isRunning($this->pidFile())) {
$server->stop($this->pidFile());
$io->success('Stopped the phpMyAdmin web server.');

return 0;
return self::SUCCESS;
}

$config = new WebServerConfig(
$this->getDocumentRoot(),
$this->documentRoot(),
'dev',
\file_get_contents($address),
$router
);

if (WebServer::STARTED === $server->start($config, $this->getPidFile())) {
if (WebServer::STARTED === $server->start($config, $this->pidFile())) {
$io->success(\sprintf('phpMyAdmin web server listening on http://%s', $config->getAddress()));
}

return 0;
return self::SUCCESS;
}

protected function getPidFile()
protected function pidFile(): string
{
return $this->getDocumentRoot().'/.pid';
return $this->documentRoot().'/.pid';
}
}
10 changes: 5 additions & 5 deletions src/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
final class SelfUpdateCommand extends Command
{
protected function configure()
protected function configure(): void
{
$this
->setName('self-update')
Expand All @@ -24,7 +24,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
Expand All @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($updater->rollback()) {
$io->success('Successfully rolled back.');

return 0;
return self::SUCCESS;
}

throw new \RuntimeException('Could not rollback.');
Expand All @@ -48,11 +48,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$updater->update()) {
$io->success(\sprintf('You are already using the latest available phpmyadmin-server (%s).', $current));

return 0;
return self::SUCCESS;
}

$io->success(\sprintf('Updated phpmyadmin-server to %s.', $updater->getNewVersion()));

return 0;
return self::SUCCESS;
}
}

0 comments on commit d833fae

Please sign in to comment.