Skip to content

Commit b3c87c2

Browse files
committed
Update and normalize class documentation and constructors
1 parent 1b35793 commit b3c87c2

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

packages/framework/src/Framework/Features/Navigation/NavigationItem.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,53 @@
1313
use function is_string;
1414

1515
/**
16-
* Abstraction for a navigation menu item. Used by the MainNavigationMenu and DocumentationSidebar classes.
16+
* Abstraction for a navigation menu item containing useful information like the destination, label, and priority.
17+
*
18+
* It is used by the MainNavigationMenu and DocumentationSidebar classes.
1719
*/
1820
class NavigationItem implements Stringable
1921
{
2022
protected string|Route $destination;
2123
protected string $label;
2224
protected int $priority;
2325

24-
public function __construct(Route|string $destination, string $label, int $priority = NavigationMenu::DEFAULT)
26+
/**
27+
* Create a new navigation menu item, automatically filling in the properties from a Route instance if provided.
28+
*
29+
* @param \Hyde\Support\Models\Route|string<\Hyde\Support\Models\RouteKey>|string $destination Route instance or route key, or an external URI.
30+
* @param string|null $label If not provided, Hyde will try to get it from the route's connected page, or from the URL.
31+
* @param int|null $priority If not provided, Hyde will try to get it from the route or the default priority of 500.
32+
*/
33+
public function __construct(Route|string $destination, ?string $label = null, ?int $priority = null)
2534
{
2635
[$this->destination, $this->label, $this->priority] = self::make($destination, $label, $priority);
2736
}
2837

2938
/**
3039
* Create a new navigation menu item, automatically filling in the properties from a Route instance if provided.
3140
*
32-
* @param \Hyde\Support\Models\Route|string<\Hyde\Support\Models\RouteKey>|string $destination Route instance or route key, or external URI.
33-
* @param string|null $label Leave blank to use the label of the route's corresponding page, if there is one tied to the route.
34-
* @param int|null $priority Leave blank to use the priority of the route's corresponding page, if there is one tied to the route.
41+
* @param \Hyde\Support\Models\Route|string<\Hyde\Support\Models\RouteKey>|string $destination Route instance or route key, or an external URI.
42+
* @param string|null $label If not provided, Hyde will try to get it from the route's connected page, or from the URL.
43+
* @param int|null $priority If not provided, Hyde will try to get it from the route or the default priority of 500.
3544
*/
3645
public static function create(Route|string $destination, ?string $label = null, ?int $priority = null): static
3746
{
3847
return new static(...self::make($destination, $label, $priority));
3948
}
4049

4150
/**
42-
* Resolve a link to the navigation item.
51+
* Resolve a link to the navigation item. See `getLink()` for more information.
4352
*/
4453
public function __toString(): string
4554
{
4655
return $this->getLink();
4756
}
4857

4958
/**
50-
* Resolve the destination link of the navigation item.
59+
* Resolve the destination link of the navigation item. This can then be used in the `href` attribute of an anchor tag.
60+
*
61+
* If the destination is a Route, it will be resolved using the Route's link.
62+
* Otherwise, it will be returned as is for external links using URLs.
5163
*/
5264
public function getLink(): string
5365
{
@@ -88,11 +100,13 @@ public function isActive(): bool
88100

89101
protected static function make(Route|string $destination, ?string $label = null, ?int $priority = null): array
90102
{
103+
// Automatically resolve the destination if it's a route key.
91104
if (is_string($destination) && Routes::has($destination)) {
92105
$destination = Routes::get($destination);
93106
}
94107

95108
if ($destination instanceof Route) {
109+
// Try to fill in missing properties from the route's connected page.
96110
$label ??= $destination->getPage()->navigationMenuLabel();
97111
$priority ??= $destination->getPage()->navigationMenuPriority();
98112
}

0 commit comments

Comments
 (0)