22
33namespace phpweb \Releases ;
44
5+ use DateTime ;
56use DateTimeImmutable ;
67use phpweb \Build \VarCache ;
78use function array_key_last ;
89use function array_reverse ;
910use function get_active_branches ;
10- use function get_all_branches ;
1111use function get_branch_bug_eol_date ;
12+ use function get_branch_release_date ;
1213use function get_branch_security_eol_date ;
1314
15+ /* have to force these files to be included */
16+ require_once __DIR__ . '/../../include/version.inc ' ;
17+ require_once __DIR__ . '/../../include/releases.inc ' ;
18+ require_once __DIR__ . '/../../include/branches.inc ' ;
19+
1420final class VersionData
1521{
1622 /** @var array<string, VersionData> */
@@ -22,8 +28,12 @@ final class VersionData
2228 public readonly int $ majorVersion ;
2329 public readonly int $ minorVersion ;
2430
31+ /*
32+ * Cached values that have expensive lookups
33+ */
2534 private ?DateTimeImmutable $ _bugfixEOL = null ;
2635 private ?DateTimeImmutable $ _securityEOL = null ;
36+ private ?DateTimeImmutable $ _releaseDate = null ;
2737 private ?array $ _pointReleases = null ;
2838 private ?array $ _highlightSnippets = null ;
2939
@@ -64,34 +74,29 @@ public static function getSupportedVersions(bool $includeRecentEOL = true): arra
6474 public static function all (): array
6575 {
6676 if (self ::$ _all === null ) {
67- foreach (get_all_branches () as $ branch ) {
68- self ::$ _all [$ branch ] = self ::Create ($ branch [ ' version ' ] );
77+ foreach (array_keys (ReleaseRawDataLoader:: allReleaseDataByVersionByLabel ()) as $ releaseId ) {
78+ self ::$ _all [$ releaseId ] = self ::Create ($ releaseId );
6979 }
7080 }
7181
7282 return self ::$ _all ;
7383 }
7484
75- public ?DateTimeImmutable $ bugfixEOL {
76- get {
77- if ($ this ->_bugfixEOL === null ) {
78- $ eol = get_branch_bug_eol_date ($ this ->label );
79- $ this ->_bugfixEOL = $ eol ? DateTimeImmutable::createFromInterface ($ eol ) : null ;
80- }
85+ private static function castDate (?DateTime $ date ): ?DateTimeImmutable
86+ {
87+ return $ date ? DateTimeImmutable::createFromInterface ($ date ) : null ;
88+ }
8189
82- return $ this -> _bugfixEOL ;
83- }
90+ public ? DateTimeImmutable $ releaseDate {
91+ get => $ this -> _releaseDate ??= self :: castDate ( get_branch_release_date ( $ this -> label ));
8492 }
8593
86- public ?DateTimeImmutable $ securityEOL {
87- get {
88- if ($ this ->_securityEOL === null ) {
89- $ eol = get_branch_security_eol_date ($ this ->label );
90- $ this ->_securityEOL = $ eol ? DateTimeImmutable::createFromInterface ($ eol ) : null ;
91- }
94+ public ?DateTimeImmutable $ bugfixEOL {
95+ get => $ this ->_bugfixEOL ??= self ::castDate (get_branch_bug_eol_date ($ this ->label ));
96+ }
9297
93- return $ this -> _securityEOL ;
94- }
98+ public ? DateTimeImmutable $ securityEOL {
99+ get => $ this -> _securityEOL ??= self :: castDate ( get_branch_security_eol_date ( $ this -> label ));
95100 }
96101
97102 public string $ logoUrl {
@@ -174,4 +179,29 @@ public function getMajorFeatureDescriptions(): array
174179 public string $ downloadUri {
175180 get => '/downloads.php?version= ' . $ this ->label ;
176181 }
182+
183+ public SupportState $ supportState {
184+ get {
185+ /* version 3 doesn't really exist in the data, so we assign it EOL */
186+ if ($ this ->majorVersion <= 3 ) {
187+ return SupportState::Eol;
188+ }
189+
190+ $ now = new DateTime ();
191+
192+ if ($ this ->securityEOL && $ now >= $ this ->securityEOL ) {
193+ return SupportState::Eol;
194+ }
195+
196+ if ($ this ->bugfixEOL && $ now >= $ this ->bugfixEOL ) {
197+ return SupportState::Security;
198+ }
199+
200+ if ($ this ->releaseDate && $ now >= $ this ->releaseDate ) {
201+ return SupportState::Stable;
202+ }
203+
204+ return SupportState::Future;
205+ }
206+ }
177207}
0 commit comments