-
Notifications
You must be signed in to change notification settings - Fork 26
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 #420 from bearsunday/reverse_link
Optimized reverse link
- Loading branch information
Showing
8 changed files
with
51 additions
and
6 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
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\Package\Provide\Representation; | ||
|
||
use BEAR\Resource\ReverseLinkerInterface; | ||
use BEAR\Sunday\Extension\Router\RouterInterface; | ||
|
||
use function is_string; | ||
use function parse_url; | ||
|
||
use const PHP_URL_PATH; | ||
|
||
final class RouterReverseLinker implements ReverseLinkerInterface | ||
{ | ||
public function __construct( | ||
private RouterInterface $router, | ||
) { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(string $uri, array $query): string | ||
{ | ||
$routeName = (string) parse_url($uri, PHP_URL_PATH); | ||
|
||
$reverseUri = $this->router->generate($routeName, $query); | ||
if (is_string($reverseUri)) { | ||
return $reverseUri; | ||
} | ||
|
||
return $uri; | ||
} | ||
} |
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