Skip to content

Commit c95e72c

Browse files
authored
Merge pull request #1243 from hydephp/rename-global-properties
Breaking: Rename global properties
2 parents 641df36 + e22e147 commit c95e72c

20 files changed

+145
-87
lines changed

RELEASE_NOTES.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ This serves two purposes:
1010
2. At release time, you can move the Unreleased section changes into a new release version section.
1111

1212
### Added
13-
- for new features.
13+
- Added a new `HydeKernel::currentPage()` method to return the page being rendered.
1414

1515
### Changed
16-
- for changes in existing functionality.
16+
- Renamed global `$currentRoute` and `$currentPage` variables to `$route` and `$routeKey` respectively.
17+
- Renamed `Render::getCurrentRoute()` to `Render::getRoute()` to match renamed property.
18+
- Renamed `Render::getCurrentPage()` to `Render::getRouteKey()` to match renamed property.
1719

1820
### Deprecated
21+
22+
This release candidate version contains a few deprecations, these will be removed before the final 1.0.0 release.
23+
1924
- Deprecate `RouteKey::normalize` method as it no longer performs any normalization.
25+
- Deprecate `RenderData::getCurrentRoute()` as it is renamed to `getRoute()` to match renamed property.
26+
- This change affects the `Render::getCurrentRoute()` and `Hyde::currentRoute()` facade methods.
27+
- Deprecate `RenderData::getCurrentPage()` as it is renamed to `getRouteKey()` to match renamed property.
28+
- This change affects the `Render::getCurrentPage()` and `Hyde::currentPage()` facade methods.
2029

2130
### Removed
2231
- Remove RouteKey normalization for dot notation support by @caendesilva in https://github.com/hydephp/develop/pull/1241

_ide_helper.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@
1616
/** @var \Hyde\Pages\Concerns\HydePage $page The page being compiled/previewed */
1717
$page = \Hyde\Support\Facades\Render::getPage();
1818

19-
/** @var \Hyde\Support\Models\Route $currentRoute The route for the page being compiled/previewed */
20-
$currentRoute = \Hyde\Support\Facades\Render::getCurrentRoute();
19+
/**
20+
* @var \Hyde\Support\Models\Route $currentRoute The route for the page being compiled/previewed
21+
* @deprecated Renamed to $route as "current" is implied
22+
*/
23+
$currentRoute = \Hyde\Support\Facades\Render::getRoute();
24+
25+
/**
26+
* @var string $currentPage The route key for the page being compiled/previewed
27+
* @deprecated Renamed to $routeKey as "current" is implied, and it's not a page
28+
*/
29+
$currentPage = \Hyde\Support\Facades\Render::getRouteKey();
30+
31+
/*** @var \Hyde\Support\Models\Route $currentRoute The route for the page being compiled/previewed */
32+
$route = \Hyde\Support\Facades\Render::getRoute();
2133

2234
/** @var string $currentPage The route key for the page being compiled/previewed */
23-
$currentPage = \Hyde\Support\Facades\Render::getCurrentPage();
35+
$routeKey = \Hyde\Support\Facades\Render::getRouteKey();
2436

2537
// Facades (aliased in app/config.php)
2638

packages/framework/src/Foundation/Concerns/ManagesViewData.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ public function shareViewData(HydePage $page): void
2626
/**
2727
* Get the route key for the page being rendered.
2828
*/
29-
public function currentPage(): ?string
29+
public function currentRouteKey(): ?string
3030
{
31-
return Render::getCurrentPage();
31+
return Render::getRouteKey();
3232
}
3333

3434
/**
3535
* Get the route for the page being rendered.
3636
*/
3737
public function currentRoute(): ?Route
3838
{
39-
return Render::getCurrentRoute();
39+
return Render::getRoute();
40+
}
41+
42+
/**
43+
* Get the page being rendered.
44+
*/
45+
public function currentPage(): ?HydePage
46+
{
47+
return Render::getPage();
4048
}
4149
}

packages/framework/src/Foundation/Kernel/Hyperlinks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function relativeLink(string $destination): string
7171
return $destination;
7272
}
7373

74-
$nestCount = substr_count($this->kernel->currentPage() ?? '', '/');
74+
$nestCount = substr_count($this->kernel->currentRouteKey() ?? '', '/');
7575
$route = '';
7676
if ($nestCount > 0) {
7777
$route .= str_repeat('../', $nestCount);

packages/framework/src/Support/Facades/Render.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*
1717
* @method static void setPage(HydePage $page)
1818
* @method static HydePage|null getPage()
19-
* @method static Route|null getCurrentRoute()
20-
* @method static string|null getCurrentPage()
19+
* @method static Route|null getRoute()
20+
* @method static string|null getRouteKey()
2121
* @method static void share(string $key, mixed $value)
2222
* @method static void shareToView()
2323
* @method static void clearData()

packages/framework/src/Support/Models/RenderData.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Support\Arrayable;
99
use Illuminate\Support\Facades\View;
1010
use InvalidArgumentException;
11+
use JetBrains\PhpStorm\Deprecated;
1112

1213
/**
1314
* Contains data for the current page being rendered/compiled.
@@ -20,14 +21,14 @@
2021
class RenderData implements Arrayable
2122
{
2223
protected HydePage $page;
23-
protected Route $currentRoute;
24-
protected string $currentPage;
24+
protected Route $route;
25+
protected string $routeKey;
2526

2627
public function setPage(HydePage $page): void
2728
{
2829
$this->page = $page;
29-
$this->currentRoute = $page->getRoute();
30-
$this->currentPage = $page->getRouteKey();
30+
$this->route = $page->getRoute();
31+
$this->routeKey = $page->getRouteKey();
3132

3233
$this->shareToView();
3334
}
@@ -37,14 +38,34 @@ public function getPage(): ?HydePage
3738
return $this->page ?? null;
3839
}
3940

41+
/**
42+
* @deprecated v1.0.0-RC.2 - Renamed to getRoute() to match renamed property. This method will be removed before version 1.0.
43+
* @codeCoverageIgnore
44+
*/
45+
#[Deprecated(reason: 'Renamed to getRoute() to match renamed property. This method will be removed before version 1.0.', replacement: '%class%->getRoute()')]
4046
public function getCurrentRoute(): ?Route
4147
{
42-
return $this->currentRoute ?? null;
48+
return $this->getRoute();
49+
}
50+
51+
public function getRoute(): ?Route
52+
{
53+
return $this->route ?? null;
4354
}
4455

56+
/**
57+
* @deprecated v1.0.0-RC.2 - Renamed to getRouteKey() to match renamed property. This method will be removed before version 1.0.
58+
* @codeCoverageIgnore
59+
*/
60+
#[Deprecated(reason: 'Renamed to getRoute() to match renamed property. This method will be removed before version 1.0.', replacement: '%class%->getRouteKey()')]
4561
public function getCurrentPage(): ?string
4662
{
47-
return $this->currentPage ?? null;
63+
return $this->getRouteKey();
64+
}
65+
66+
public function getRouteKey(): ?string
67+
{
68+
return $this->routeKey ?? null;
4869
}
4970

5071
public function shareToView(): void
@@ -64,8 +85,8 @@ public function share(string $key, mixed $value): void
6485

6586
public function clearData(): void
6687
{
67-
unset($this->page, $this->currentRoute, $this->currentPage);
68-
View::share(['page' => null, 'currentRoute' => null, 'currentPage' => null]);
88+
unset($this->page, $this->route, $this->routeKey);
89+
View::share(['page' => null, 'route' => null, 'routeKey' => null]);
6990
}
7091

7192
/**
@@ -76,8 +97,8 @@ public function toArray(): array
7697
return [
7798
'render' => $this,
7899
'page' => $this->getPage(),
79-
'currentRoute' => $this->getCurrentRoute(),
80-
'currentPage' => $this->getCurrentPage(),
100+
'route' => $this->getRoute(),
101+
'routeKey' => $this->getRouteKey(),
81102
];
82103
}
83104
}

packages/framework/tests/Feature/DarkmodeFeatureTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function test_layout_has_toggle_button_and_script_when_enabled()
4747
$view = view('hyde::layouts/page')->with([
4848
'title' => 'foo',
4949
'content' => 'foo',
50-
'currentPage' => 'foo',
50+
'routeKey' => 'foo',
5151
])->render();
5252

5353
$this->assertStringContainsString('title="Toggle theme"', $view);
@@ -66,7 +66,7 @@ public function test_documentation_page_has_toggle_button_and_script_when_enable
6666
$view = view('hyde::layouts/docs')->with([
6767
'title' => 'foo',
6868
'content' => 'foo',
69-
'currentPage' => 'foo',
69+
'routeKey' => 'foo',
7070
])->render();
7171

7272
$this->assertStringContainsString('title="Toggle theme"', $view);
@@ -83,7 +83,7 @@ public function test_dark_mode_theme_button_is_hidden_in_layouts_when_disabled()
8383
$view = view('hyde::layouts/page')->with([
8484
'title' => 'foo',
8585
'content' => 'foo',
86-
'currentPage' => 'foo',
86+
'routeKey' => 'foo',
8787
])->render();
8888

8989
$this->assertStringNotContainsString('title="Toggle theme"', $view);
@@ -101,7 +101,7 @@ public function test_dark_mode_theme_button_is_hidden_in_documentation_pages_whe
101101
$view = view('hyde::layouts/docs')->with([
102102
'title' => 'foo',
103103
'content' => 'foo',
104-
'currentPage' => 'foo',
104+
'routeKey' => 'foo',
105105
])->render();
106106

107107
$this->assertStringNotContainsString('title="Toggle theme"', $view);

packages/framework/tests/Feature/GlobalMetadataBagTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function test_metadata_existing_in_the_current_page_is_not_added()
119119
$page = new MarkdownPage('foo');
120120
$page->metadata->add($duplicate);
121121

122-
Render::share('currentPage', 'foo');
122+
Render::share('routeKey', 'foo');
123123
Render::share('page', $page);
124124

125125
$this->assertEquals(['metadata:keep' => $keep], GlobalMetadataBag::make()->get());
@@ -134,7 +134,7 @@ public function test_metadata_existing_in_the_current_page_is_not_added_regardle
134134
$page = new MarkdownPage('foo');
135135
$page->metadata->add(Meta::name('foo', 'baz'));
136136

137-
Render::share('currentPage', 'foo');
137+
Render::share('routeKey', 'foo');
138138
Render::share('page', $page);
139139

140140
$this->assertEquals([], GlobalMetadataBag::make()->get());

packages/framework/tests/Feature/HydeKernelTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Hyde\Framework\HydeServiceProvider;
1414
use Hyde\Hyde;
1515
use Hyde\Pages\BladePage;
16+
use Hyde\Pages\Concerns\HydePage;
1617
use Hyde\Pages\DocumentationPage;
1718
use Hyde\Pages\InMemoryPage;
1819
use Hyde\Pages\MarkdownPage;
@@ -79,17 +80,24 @@ public function test_has_feature_helper_calls_method_on_features_class()
7980

8081
public function test_current_page_helper_returns_current_page_name()
8182
{
82-
Render::share('currentPage', 'foo');
83-
$this->assertSame('foo', Hyde::currentPage());
83+
Render::share('routeKey', 'foo');
84+
$this->assertSame('foo', Hyde::currentRouteKey());
8485
}
8586

8687
public function test_current_route_helper_returns_current_route_object()
8788
{
8889
$expected = new Route(new MarkdownPage());
89-
Render::share('currentRoute', $expected);
90+
Render::share('route', $expected);
9091
$this->assertInstanceOf(Route::class, Hyde::currentRoute());
9192
$this->assertSame($expected, Hyde::currentRoute());
92-
$this->assertSame($expected, Hyde::currentRoute());
93+
}
94+
95+
public function test_current_page_helper_returns_current_page_object()
96+
{
97+
$expected = new MarkdownPage();
98+
Render::share('page', $expected);
99+
$this->assertInstanceOf(HydePage::class, Hyde::currentPage());
100+
$this->assertSame($expected, Hyde::currentPage());
93101
}
94102

95103
public function test_make_title_helper_returns_title_from_page_slug()
@@ -151,29 +159,29 @@ public function test_format_html_path_helper_formats_path_according_to_config_ru
151159

152160
public function test_relative_link_helper_returns_relative_link_to_destination()
153161
{
154-
Render::share('currentPage', 'bar');
162+
Render::share('routeKey', 'bar');
155163
$this->assertSame('foo', Hyde::relativeLink('foo'));
156164

157-
Render::share('currentPage', 'foo/bar');
165+
Render::share('routeKey', 'foo/bar');
158166
$this->assertSame('../foo', Hyde::relativeLink('foo'));
159167
}
160168

161169
public function test_media_link_helper_returns_relative_link_to_destination()
162170
{
163-
Render::share('currentPage', 'bar');
171+
Render::share('routeKey', 'bar');
164172
$this->assertSame('media/foo', Hyde::mediaLink('foo'));
165173

166-
Render::share('currentPage', 'foo/bar');
174+
Render::share('routeKey', 'foo/bar');
167175
$this->assertSame('../media/foo', Hyde::mediaLink('foo'));
168176
}
169177

170178
public function test_image_helper_returns_image_path_for_given_name()
171179
{
172-
Render::share('currentPage', 'foo');
180+
Render::share('routeKey', 'foo');
173181
$this->assertSame('media/foo.jpg', Hyde::asset('foo.jpg'));
174182
$this->assertSame('https://example.com/foo.jpg', Hyde::asset('https://example.com/foo.jpg'));
175183

176-
Render::share('currentPage', 'foo/bar');
184+
Render::share('routeKey', 'foo/bar');
177185
$this->assertSame('../media/foo.jpg', Hyde::asset('foo.jpg'));
178186
$this->assertSame('https://example.com/foo.jpg', Hyde::asset('https://example.com/foo.jpg'));
179187
}

0 commit comments

Comments
 (0)