Skip to content

Commit

Permalink
Merge pull request #43 from sunrise-php/release/v2.0.2
Browse files Browse the repository at this point in the history
release v2.0.2
  • Loading branch information
fenric committed Jan 6, 2020
2 parents bb89159 + e9c8398 commit e74eb26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
class Route implements RouteInterface
{

/**
* Server Request attribute name for the route instance
*
* @var string
*/
public const ATTR_NAME_FOR_ROUTE = '@route';

/**
* Server Request attribute name for the route name
*
Expand Down Expand Up @@ -287,6 +294,7 @@ public function withAddedAttributes(array $attributes) : RouteInterface
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$request = $request->withAttribute(self::ATTR_NAME_FOR_ROUTE, $this);
$request = $request->withAttribute(self::ATTR_NAME_FOR_ROUTE_NAME, $this->name);

foreach ($this->attributes as $key => $value) {
Expand Down
6 changes: 5 additions & 1 deletion tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ public function testHandle() : void
$this->assertTrue($route->getMiddlewares()[2]->isRunned());
$this->assertTrue($route->getRequestHandler()->isRunned());

$expectedAttributes = [Route::ATTR_NAME_FOR_ROUTE_NAME => $route->getName()];
$expectedAttributes = [
Route::ATTR_NAME_FOR_ROUTE => $route,
Route::ATTR_NAME_FOR_ROUTE_NAME => $route->getName(),
];

$expectedAttributes += $route->getAttributes();

$this->assertSame($expectedAttributes, $route->getRequestHandler()->getAttributes());
Expand Down

0 comments on commit e74eb26

Please sign in to comment.