-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1636 from hydephp/create-new-navigation-destinati…
…on-class [2.x] Create new navigation destination class to replace external routes
- Loading branch information
Showing
9 changed files
with
73 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/framework/src/Framework/Features/Navigation/NavigationDestination.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Framework\Features\Navigation; | ||
|
||
use Stringable; | ||
use Hyde\Support\Models\Route; | ||
use Hyde\Foundation\Facades\Routes; | ||
|
||
use function is_string; | ||
|
||
class NavigationDestination implements Stringable | ||
{ | ||
protected Route|string $destination; | ||
|
||
public function __construct(Route|string $destination) | ||
{ | ||
if (is_string($destination) && Routes::has($destination)) { | ||
$destination = Routes::get($destination); | ||
} | ||
|
||
$this->destination = $destination; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->getLink(); | ||
} | ||
|
||
public function getLink(): string | ||
{ | ||
return (string) $this->destination; | ||
} | ||
|
||
/** @experimental */ | ||
public function getRoute(): ?Route | ||
{ | ||
return $this->destination instanceof Route ? $this->destination : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters