Skip to content

Commit

Permalink
Merge branch 'l0gicgate/4.x-RouteInvocationStrategySetter' into 4.x
Browse files Browse the repository at this point in the history
Closes #2634
  • Loading branch information
akrabat committed Apr 20, 2019
2 parents 6aa3c6c + 2cf746c commit 341e1bd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## 4.0.0 - TBD

### Added
- [#2634](https://github.com/slimphp/Slim/pull/2634) Added ability to set invocation strategy on a per-route basis.
- [#2555](https://github.com/slimphp/Slim/pull/2555) Added PSR-15 Middleware Support
- [#2529](https://github.com/slimphp/Slim/pull/2529) Slim no longer ships with a PSR-7 implementation. You need to provide a PSR-7 ServerRequest and a PSR-17 ResponseFactory to run Slim.
- [#2507](https://github.com/slimphp/Slim/pull/2507) Method names are now case-sensitive in Router::map(), and so, by extension, in App::map()
Expand Down
8 changes: 8 additions & 0 deletions Slim/Interfaces/RouteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ interface RouteInterface
*/
public function getInvocationStrategy(): InvocationStrategyInterface;

/**
* Set route invocation strategy
*
* @param InvocationStrategyInterface $invocationStrategy
* @return RouteInterface
*/
public function setInvocationStrategy(InvocationStrategyInterface $invocationStrategy): RouteInterface;

/**
* Get route methods
*
Expand Down
9 changes: 9 additions & 0 deletions Slim/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public function getInvocationStrategy(): InvocationStrategyInterface
return $this->invocationStrategy;
}

/**
* {@inheritdoc}
*/
public function setInvocationStrategy(InvocationStrategyInterface $invocationStrategy): RouteInterface
{
$this->invocationStrategy = $invocationStrategy;
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/Routing/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ public function testGetInvocationStrategy()
$this->assertEquals($strategy, $route->getInvocationStrategy());
}

public function testSetInvocationStrategy()
{
$callable = function (ServerRequestInterface $request, ResponseInterface $response, $args) {
return $response;
};

$responseFactory = $this->getResponseFactory();
$callableResolver = new CallableResolver();
$strategy = new RequestResponse();

$route = new Route(['GET'], '/', $callable, $responseFactory, $callableResolver);
$route->setInvocationStrategy($strategy);

$this->assertSame($strategy, $route->getInvocationStrategy());
}

public function testGetGroups()
{
$callable = function (ServerRequestInterface $request, ResponseInterface $response, $args) {
Expand Down

0 comments on commit 341e1bd

Please sign in to comment.