Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use latest version from auto-incrementing file #76

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function execute(
): int {
try {
// Print intro
$output->writeln(\sprintf('<fg=yellow;options=bold>%s</> <info>v%s</>', Info::NAME, Info::VERSION));
$output->writeln(\sprintf('<fg=yellow;options=bold>%s</> <info>v%s</>', Info::NAME, Info::version()));
$output->write(Info::LOGO_CLI_COLOR . "\n", true, OutputInterface::OUTPUT_RAW);

/** @var non-empty-string[] $senders */
Expand Down
20 changes: 19 additions & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class Info
{
public const NAME = 'Buggregator Trap';
public const VERSION = '1.7.0';
public const LOGO_CLI_COLOR = <<<CONSOLE
\e[44;97;1m \e[0m
\e[44;97;1m ▄█▀ ▀█▄ \e[0m
Expand All @@ -27,4 +26,23 @@ class Info
CONSOLE;

public const TRAP_ROOT = __DIR__ . '/..';
private const VERSION = 'experimental';

public static function version(): string
{
$versionPath = self::TRAP_ROOT . '/src/version.json';
$versionContents = file_get_contents($versionPath);

if ($versionContents === false) {
return self::VERSION;
}

$versionData = json_decode($versionContents, true);

if (!is_array($versionData) || !isset($versionData['.']) || !is_string($versionData['.'])) {
return self::VERSION;
}

return $versionData['.'];
}
}
2 changes: 1 addition & 1 deletion src/Sender/Frontend/Message/Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function jsonSerialize(): array
{
return [
'client' => $this->client,
'version' => Info::VERSION,
'version' => Info::version(),
'subs' => [
'events' => (object) [],
],
Expand Down
11 changes: 7 additions & 4 deletions src/Sender/Frontend/Message/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
final class Settings implements JsonSerializable
{
public function __construct(
public readonly string $number = Info::VERSION,
) {}
public readonly string $number;

public function __construct()
{
$this->number = Info::version();
}

public function jsonSerialize(): array
{
Expand All @@ -23,7 +26,7 @@ public function jsonSerialize(): array
'enabled' => false,
'login_url' => '/auth/sso/login',
],
'version' => Info::VERSION,
'version' => $this->number,
];
}
}
9 changes: 6 additions & 3 deletions src/Sender/Frontend/Message/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
final class Version implements JsonSerializable
{
public function __construct(
public readonly string $number = Info::VERSION,
) {}
public readonly string $number;

public function __construct()
{
$this->number = Info::version();
}

public function jsonSerialize(): array
{
Expand Down
4 changes: 3 additions & 1 deletion src/Sender/RemoteSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ final class RemoteSender extends SocketSender
{
private string $uuid;

private readonly string $clientVersion;

public function __construct(
string $uuid = null,
string $host = '127.0.0.1',
int $port = 9912,
private readonly string $clientVersion = Info::VERSION,
) {
$this->clientVersion = Info::version();
$this->uuid = $uuid ?? Uuid::generate();

parent::__construct($host, $port);
Expand Down
Loading