| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Upgrades; |
| 6 |
|
| 7 |
use Yatra\Upgrades\Contracts\UpgradeStepInterface; |
| 8 |
use Yatra\Upgrades\Versions\Upgrade_3_0_3; |
| 9 |
use Yatra\Upgrades\Versions\Upgrade_3_0_5; |
| 10 |
|
| 11 |
/** |
| 12 |
* Register Free upgrade steps (add a class per release when DB/data migration is required). |
| 13 |
* |
| 14 |
* Each step’s {@see UpgradeStepInterface::targetVersion()} is the release that introduced the |
| 15 |
* migration (e.g. 3.0.3), not necessarily the current plugin version constant; the runner still applies |
| 16 |
* all applicable steps when upgrading from an older stored `yatra_version` to the current code. |
| 17 |
* |
| 18 |
* @return list<class-string<UpgradeStepInterface>> |
| 19 |
*/ |
| 20 |
final class FreeUpgradeRegistry |
| 21 |
{ |
| 22 |
/** |
| 23 |
* @return list<class-string<UpgradeStepInterface>> |
| 24 |
*/ |
| 25 |
public static function allSteps(): array |
| 26 |
{ |
| 27 |
return [ |
| 28 |
Upgrade_3_0_3::class, |
| 29 |
Upgrade_3_0_5::class, |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @return list<class-string<UpgradeStepInterface>> |
| 35 |
*/ |
| 36 |
public static function stepsForHook(string $hook): array |
| 37 |
{ |
| 38 |
$out = []; |
| 39 |
foreach (self::allSteps() as $class) { |
| 40 |
if (in_array($hook, $class::runOnHooks(), true)) { |
| 41 |
$out[] = $class; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
// version_compare() with two args returns -1 / 0 / 1 — exactly |
| 46 |
// what usort wants. Passing '<=>' as the operator (legacy mistake) |
| 47 |
// throws a ValueError under PHP 8+ since '<=>' isn't in the |
| 48 |
// operator allowlist; pre-PHP 8 it silently returned null and |
| 49 |
// usort would have produced an unstable ordering anyway. |
| 50 |
usort($out, static function (string $a, string $b): int { |
| 51 |
return version_compare($a::targetVersion(), $b::targetVersion()); |
| 52 |
}); |
| 53 |
|
| 54 |
return $out; |
| 55 |
} |
| 56 |
} |
| 57 |
|