Add the PhpMyAdmin\Version class generator
Creates the PhpMyAdmin\Command\SetVersionCommand class. Usage: ./scripts/console set-version 5.1.0-dev Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
f28fbe06e4
commit
92965c6945
101
libraries/classes/Command/SetVersionCommand.php
Normal file
101
libraries/classes/Command/SetVersionCommand.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Command;
|
||||
|
||||
use RangeException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use function file_put_contents;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
|
||||
final class SetVersionCommand extends Command
|
||||
{
|
||||
/** @var string */
|
||||
protected static $defaultName = 'set-version';
|
||||
|
||||
/** @var string */
|
||||
private static $generatedClassTemplate = <<<'PHP'
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
/**
|
||||
* This class is generated by scripts/console.
|
||||
*
|
||||
* @see \PhpMyAdmin\Command\SetVersionCommand
|
||||
*/
|
||||
final class Version
|
||||
{
|
||||
// The VERSION_SUFFIX constant is defined at libraries/vendor_config.php
|
||||
public const VERSION = '%1$u.%2$u.%3$u%4$s' . VERSION_SUFFIX;
|
||||
public const SERIES = '%1$u.%2$u';
|
||||
public const MAJOR = %1$u;
|
||||
public const MINOR = %2$u;
|
||||
public const PATCH = %3$u;
|
||||
public const ID = %1$u%2$02u%3$02u;
|
||||
public const PRE_RELEASE_NAME = '%5$s';
|
||||
public const IS_DEV = %6$s;
|
||||
}
|
||||
|
||||
PHP;
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setDescription('Sets the version number');
|
||||
$this->setHelp('This command generates the PhpMyAdmin\Version class based on the version number provided.');
|
||||
$this->addArgument('version', InputArgument::REQUIRED, 'The version number');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
/** @var string $version */
|
||||
$version = $input->getArgument('version');
|
||||
|
||||
$generatedClass = $this->getGeneratedClass($version);
|
||||
|
||||
if (! $this->writeGeneratedClassFile($generatedClass)) {
|
||||
// failure
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('PhpMyAdmin\Version class successfully generated!');
|
||||
|
||||
// success
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getGeneratedClass(string $version): string
|
||||
{
|
||||
$return = preg_match('/^(\d+)\.(\d{1,2})\.(\d{1,2})(-(\w+))?$/', $version, $matches);
|
||||
if ($return === false || $return === 0) {
|
||||
throw new RangeException('The version number is in the wrong format: ' . $version);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
self::$generatedClassTemplate,
|
||||
$matches[1],
|
||||
$matches[2],
|
||||
$matches[3],
|
||||
$matches[4] ?? '',
|
||||
$matches[5] ?? '',
|
||||
($matches[5] ?? '') === 'dev' ? 'true' : 'false'
|
||||
);
|
||||
}
|
||||
|
||||
private function writeGeneratedClassFile(string $generatedClass): bool
|
||||
{
|
||||
$result = file_put_contents(
|
||||
ROOT_PATH . 'libraries/classes/Version.php',
|
||||
$generatedClass
|
||||
);
|
||||
|
||||
return $result !== false;
|
||||
}
|
||||
}
|
||||
@ -137,8 +137,8 @@ class Config
|
||||
public function checkSystem(): void
|
||||
{
|
||||
// All the version handling is now done in the Version class
|
||||
$this->set('PMA_VERSION', Version::phpMyAdminVersion());
|
||||
$this->set('PMA_MAJOR_VERSION', Version::phpMyAdminSeriesVersion());
|
||||
$this->set('PMA_VERSION', Version::VERSION);
|
||||
$this->set('PMA_MAJOR_VERSION', Version::SERIES);
|
||||
|
||||
$this->checkWebServerOs();
|
||||
$this->checkWebServer();
|
||||
|
||||
@ -4,64 +4,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use function defined;
|
||||
|
||||
/**
|
||||
* Class to handle the phpMyAdmin version
|
||||
* This class is generated by scripts/console.
|
||||
*
|
||||
* @see \PhpMyAdmin\Command\SetVersionCommand
|
||||
*/
|
||||
final class Version
|
||||
{
|
||||
/*
|
||||
* Packaging people can add a version suffix using the VERSION_SUFFIX constant at vendor_config.php
|
||||
*/
|
||||
|
||||
public const VERSION_MAJOR = 5;
|
||||
public const VERSION_MINOR = 1;
|
||||
public const VERSION_PATCH = 0;
|
||||
|
||||
// The version will be {major}.{minor}.{patch}-dev
|
||||
// The VERSION_SUFFIX constant is defined at libraries/vendor_config.php
|
||||
public const VERSION = '5.1.0-dev' . VERSION_SUFFIX;
|
||||
public const SERIES = '5.1';
|
||||
public const MAJOR = 5;
|
||||
public const MINOR = 1;
|
||||
public const PATCH = 0;
|
||||
public const ID = 50100;
|
||||
public const PRE_RELEASE_NAME = 'dev';
|
||||
public const IS_DEV = true;
|
||||
|
||||
// The version will be {major}.{minor}.{patch}-{PRE_RELEASE_NAME} if not empty
|
||||
public const PRE_RELEASE_NAME = '';
|
||||
|
||||
/**
|
||||
* Get the current phpMyAdmin series version
|
||||
*
|
||||
* @example 5.1
|
||||
*/
|
||||
public static function phpMyAdminSeriesVersion(): string
|
||||
{
|
||||
return self::VERSION_MAJOR . '.' . self::VERSION_MINOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current phpMyAdmin version
|
||||
*/
|
||||
public static function phpMyAdminVersion(): string
|
||||
{
|
||||
$versionRaw = self::VERSION_MAJOR . '.' . self::VERSION_MINOR . '.' . self::VERSION_PATCH;
|
||||
|
||||
if (self::IS_DEV) {
|
||||
return $versionRaw . '-dev';
|
||||
}
|
||||
|
||||
if (self::PRE_RELEASE_NAME !== '') {
|
||||
return $versionRaw . '-' . self::PRE_RELEASE_NAME;
|
||||
}
|
||||
|
||||
if (defined('VERSION_SUFFIX')) {
|
||||
return $versionRaw . VERSION_SUFFIX;
|
||||
}
|
||||
|
||||
return $versionRaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the current version is a dev version
|
||||
*/
|
||||
public static function isDev(): bool
|
||||
{
|
||||
return self::IS_DEV;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
<?php
|
||||
|
||||
use PhpMyAdmin\Command\CacheWarmupCommand;
|
||||
use PhpMyAdmin\Command\SetVersionCommand;
|
||||
use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Tests\Stubs\DbiDummy;
|
||||
@ -65,5 +66,6 @@ $application = new Application('phpMyAdmin Console Tool');
|
||||
|
||||
$application->add(new CacheWarmupCommand());
|
||||
$application->add(new LintCommand($twig));
|
||||
$application->add(new SetVersionCommand());
|
||||
|
||||
$application->run();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user