Skip to content

Commit

Permalink
Merge pull request #513 from hydephp/510-normalize-route-keys-so-dot-…
Browse files Browse the repository at this point in the history
…notation-can-be-used

Update route keys to support dot notation hydephp/develop@505b8b2
  • Loading branch information
github-actions committed Sep 13, 2022
1 parent d9f0056 commit 76113e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Models/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,15 @@ public static function get(string $routeKey): static
/**
* Get a route from the route index for the specified route key.
*
* @param string $routeKey Example: posts/foo.md
* @param string $routeKey Example: posts/foo, posts.foo
* @return \Hyde\Framework\Models\Route
*
* @throws \Hyde\Framework\Exceptions\RouteNotFoundException
*/
public static function getFromKey(string $routeKey): static
{
return Hyde::routes()->get($routeKey) ?? throw new RouteNotFoundException($routeKey);
return Hyde::routes()->get(str_replace('.', '/', $routeKey))
?? throw new RouteNotFoundException($routeKey);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public function test_get_from_model_returns_the_models_route()
$this->assertEquals(new Route($page), Route::getFromModel($page));
}

public function test_get_supports_dot_notation()
{
$this->file('_posts/foo.md');
$this->assertSame(Route::get('posts/foo'), Route::get('posts.foo'));
}

public function test_route_facade_all_method_returns_all_routes()
{
$this->assertEquals(Hyde::routes(), Route::all());
Expand Down

0 comments on commit 76113e1

Please sign in to comment.