From 225a8ca55cdca5392745383db9d5bed9dacf550d Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sat, 13 Jul 2024 21:20:11 +0200 Subject: [PATCH] Introduce versions class --- README.md | 10 +++++++--- composer.json | 3 +++ etc/Versions.php.twig | 10 ++++++++++ src/Versions.php | 10 ++++++++++ src/versions.php | 14 +++++++------- tools/generate.php | 38 ++++++++++++++++++++++++++++++-------- 6 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 etc/Versions.php.twig create mode 100644 src/Versions.php diff --git a/README.md b/README.md index 8023526..ed7971f 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,13 @@ composer require wyrihaximus/fake-php-version ## Available constants ## -* `WyriHaximus\FakePHPVersion\FUTURE` - Version in the next mayor version of PHP e.g. 8.98.9001 -* `WyriHaximus\FakePHPVersion\CURRENT` - Version in the current mayor version of PHP e.g. 7.133.666 -* `WyriHaximus\FakePHPVersion\ACTUAL` - Actual current version of PHP +* `WyriHaximus\FakePHPVersion\Versions::FUTURE` - Version in the next mayor version of PHP e.g. 8.98.9001 +* `WyriHaximus\FakePHPVersion\Versions::CURRENT` - Version in the current mayor version of PHP e.g. 7.133.666 +* `WyriHaximus\FakePHPVersion\Versions::ACTUAL` - Actual current version of PHP + +The `WyriHaximus\FakePHPVersion\FUTURE`, `WyriHaximus\FakePHPVersion\Versions::CURRENT`, and +`WyriHaximus\FakePHPVersion\Versions::ACTUAL` constants are still available but deprecated. v2 will drop them and be +`Versions` class only. ## License ## diff --git a/composer.json b/composer.json index 8730bea..b68a8a6 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,9 @@ "sort-packages": true }, "autoload": { + "psr-4": { + "WyriHaximus\\FakePHPVersion\\": "src/" + }, "files": [ "src/versions_include.php" ] diff --git a/etc/Versions.php.twig b/etc/Versions.php.twig new file mode 100644 index 0000000..db98631 --- /dev/null +++ b/etc/Versions.php.twig @@ -0,0 +1,10 @@ + [ @@ -23,12 +23,12 @@ if (count($shouldBe3) === 3) { $actualVersion = implode('.', $shouldBe3); - if (ACTUAL === $actualVersion) { + if (Versions::ACTUAL === $actualVersion) { echo 'No new version detected, better luck next time!', PHP_EOL; exit(2); } - $constantFutureVersion = explode('.', FUTURE); + $constantFutureVersion = explode('.', Versions::FUTURE); $futureVersion = $shouldBe3; $futureVersion[0]++; if ($futureVersion[0] === $shouldBe3[0]) { @@ -41,7 +41,7 @@ $futureVersion[2] += $constantFutureVersion[1]; $futureVersion = implode('.', $futureVersion); - $constantCurrentVersion = explode('.', CURRENT); + $constantCurrentVersion = explode('.', Versions::CURRENT); $currentVersion = $shouldBe3; if ($currentVersion[0] !== $shouldBe3[0]) { $currentVersion[0]++; @@ -67,7 +67,29 @@ file_put_contents( dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'versions.php', - " $futureVersion, + 'current' => $currentVersion, + 'actual' => $actualVersion, + ] + ), + ); + file_put_contents( + dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Versions.php', + render( + file_get_contents( + dirname(__DIR__) . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'Versions.php.twig', + ), + [ + 'future' => $futureVersion, + 'current' => $currentVersion, + 'actual' => $actualVersion, + ] + ), ); exit(0); }