File tree Expand file tree Collapse file tree 3 files changed +76
-10
lines changed
Expand file tree Collapse file tree 3 files changed +76
-10
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \GitHub ;
4+
5+ //
6+
7+ use DateTimeImmutable ;
8+ use Tempest \Cache \Cache ;
9+ use Tempest \Core \Kernel ;
10+ use Tempest \HttpClient \HttpClient ;
11+ use Throwable ;
12+
13+ final class GetLatestRelease
14+ {
15+ public function __construct (
16+ private HttpClient $ httpClient ,
17+ private Cache $ cache ,
18+ ) {
19+ }
20+
21+ public function __invoke (): ?string
22+ {
23+ return $ this ->cache ->resolve (
24+ key: 'tempest-latest-release ' ,
25+ cache: function () {
26+ // Default release to the currently running version of Tempest.
27+ $ defaultRelease = sprintf ('v%s ' , Kernel::VERSION );
28+
29+ try {
30+ $ body = $ this ->httpClient ->get ('https://api.github.com/repos/tempestphp/tempest-framework/releases/latest ' )->body ;
31+
32+ return json_decode ($ body )->tag_name ?? $ defaultRelease ;
33+ } catch (Throwable $ e ) {
34+ ll ($ e );
35+ return Kernel::VERSION ;
36+ }
37+ },
38+ expiresAt: new DateTimeImmutable ('+12 hours ' ),
39+ );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Web ;
4+
5+ use App \GitHub \GetLatestRelease ;
6+ use Tempest \View \View ;
7+ use Tempest \View \ViewProcessor ;
8+
9+ final readonly class LatestReleaseViewProcessor implements ViewProcessor
10+ {
11+ public function __construct (
12+ private GetLatestRelease $ getLatestRelease ,
13+ ) {
14+ }
15+
16+ #[\Override]
17+ public function process (View $ view ): View
18+ {
19+ return $ view ->data (latest_release: ($ this ->getLatestRelease )());
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -15,16 +15,20 @@ class="group w-full lg:max-w-5xl xl:max-w-7xl 2xl:max-w-8xl fixed lg:rounded-xl
1515 id="header"
1616 >
1717 <!-- Left side -->
18- <a href="/" class="flex items-center gap-4">
19- <!-- Logo -->
20- <div class="size-8">
21- <img src="/img/logo-transparent.svg" alt="Tempest logo" class="size-full" />
22- </div>
23- <span class="font-medium hidden lg:inline">Tempest</span>
24- <span class="hidden md:inline text-xs tracking-wide font-medium text-(--ui-text-muted) bg-(--ui-bg)/50 px-2 py-1 rounded-lg border border-(--ui-border)">
25- v{{ \Tempest\Core\Kernel::VERSION }}
26- </span>
27- </a>
18+ <div class="flex items-center gap-4">
19+ <a href="/" class="flex items-center gap-4">
20+ <!-- Logo -->
21+ <div class="size-8">
22+ <img src="/img/logo-transparent.svg" alt="Tempest logo" class="size-full" />
23+ </div>
24+ <span class="font-medium hidden lg:inline">Tempest</span>
25+ </a>
26+
27+ <a class="hidden md:inline text-xs tracking-wide font-medium text-(--ui-text-muted) bg-(--ui-bg)/50 px-2 py-1 rounded-lg border border-(--ui-border)" href="https://github.com/tempestphp/tempest-framework/releases/{{ $latest_release }}">
28+ {{ $latest_release }}
29+ </a>
30+ </div>
31+
2832 <!-- Center -->
2933 <div class="flex items-center gap-4">
3034 <x-search />
You can’t perform that action at this time.
0 commit comments