Skip to content

Commit

Permalink
Merge pull request #125 from WyriHaximus/introduce-versions-class
Browse files Browse the repository at this point in the history
Introduce versions class
  • Loading branch information
WyriHaximus authored Jul 13, 2024
2 parents 458b11f + 225a8ca commit a3c6bad
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"sort-packages": true
},
"autoload": {
"psr-4": {
"WyriHaximus\\FakePHPVersion\\": "src/"
},
"files": [
"src/versions_include.php"
]
Expand Down
10 changes: 10 additions & 0 deletions etc/Versions.php.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace WyriHaximus\FakePHPVersion;
final class Versions
{
const FUTURE = '{{ future }}';
const CURRENT = '{{ current }}';
const ACTUAL = '{{ actual }}';
}
10 changes: 10 additions & 0 deletions src/Versions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace WyriHaximus\FakePHPVersion;

final class Versions
{
const FUTURE = '9.426.438';
const CURRENT = '8.468.486';
const ACTUAL = '8.3.9';
}
14 changes: 7 additions & 7 deletions src/versions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace WyriHaximus\FakePHPVersion;

const FUTURE = '9.420.440';
const CURRENT = '8.459.452';
const ACTUAL = '8.3.8';
<?php

namespace WyriHaximus\FakePHPVersion;

const FUTURE = '9.426.438';
const CURRENT = '8.468.486';
const ACTUAL = '8.3.9';
38 changes: 30 additions & 8 deletions tools/generate.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use const WyriHaximus\FakePHPVersion\ACTUAL;
use const WyriHaximus\FakePHPVersion\CURRENT;
use const WyriHaximus\FakePHPVersion\FUTURE;
use WyriHaximus\FakePHPVersion\Versions;

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'versions_include.php';
use function WyriHaximus\Twig\render;

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

$context = stream_context_create([
'http' => [
Expand All @@ -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]) {
Expand All @@ -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]++;
Expand All @@ -67,7 +67,29 @@

file_put_contents(
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'versions.php',
"<?php\r\n\r\nnamespace WyriHaximus\FakePHPVersion;\r\n\r\nconst FUTURE = '" . $futureVersion . "';\r\nconst CURRENT = '" . $currentVersion . "';\r\nconst ACTUAL = '" . $actualVersion . "';\r\n"
render(
file_get_contents(
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'versions.php.twig',
),
[
'future' => $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);
}
Expand Down

0 comments on commit a3c6bad

Please sign in to comment.