Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/60-http-method-any-constant' into release-3.0.0
Browse files Browse the repository at this point in the history
Close #60
  • Loading branch information
weierophinney committed Mar 7, 2018
2 parents c4380e0 + d7765c8 commit 3b21fb4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ All notable changes to this project will be documented in this file, in reverse
list of HTTP methods provided to it is empty. Routes MUST have one or more
HTTP methods associated.

- [#60](https://github.com/zendframework/zend-expressive-router/pull/60) changes
the behavior of the `RouteResult::getAllowedMethods()` to allow a nullable
return value; this will return `null` if all methods are allowed.

### Deprecated

- Nothing.
Expand Down
17 changes: 5 additions & 12 deletions src/RouteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class RouteResult implements MiddlewareInterface
{
/**
* @var array
* @var null|string[]
*/
private $allowedMethods = [];

Expand Down Expand Up @@ -88,14 +88,7 @@ public static function fromRouteFailure(?array $methods) : self
{
$result = new self();
$result->success = false;

if ($methods === Route::HTTP_METHOD_ANY) {
$result->allowedMethods = ['*'];
}

if (is_array($methods)) {
$result->allowedMethods = $methods;
}
$result->allowedMethods = $methods;

return $result;
}
Expand Down Expand Up @@ -180,7 +173,7 @@ public function isFailure() : bool
*/
public function isMethodFailure() : bool
{
if ($this->isSuccess() || ['*'] === $this->allowedMethods) {
if ($this->isSuccess() || $this->allowedMethods === Route::HTTP_METHOD_ANY) {
return false;
}

Expand All @@ -190,9 +183,9 @@ public function isMethodFailure() : bool
/**
* Retrieve the allowed methods for the route failure.
*
* @return string[] HTTP methods allowed
* @return null|string[] HTTP methods allowed
*/
public function getAllowedMethods() : array
public function getAllowedMethods() : ?array
{
if ($this->isSuccess()) {
return $this->route
Expand Down
4 changes: 2 additions & 2 deletions test/RouteResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testRouteNameIsNotRetrievable()
public function testRouteFailureRetrieveAllHttpMethods()
{
$result = RouteResult::fromRouteFailure(Route::HTTP_METHOD_ANY);
$this->assertSame(['*'], $result->getAllowedMethods());
$this->assertSame(Route::HTTP_METHOD_ANY, $result->getAllowedMethods());
}

public function testRouteFailureRetrieveHttpMethods()
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testFailureResultDoesNotIndicateAMethodFailureIfAllMethodsAreAll
public function testAllowedMethodsIncludesASingleWildcardEntryWhenAllMethodsAllowedForFailureResult(
RouteResult $result
) {
$this->assertSame(['*'], $result->getAllowedMethods());
$this->assertSame(Route::HTTP_METHOD_ANY, $result->getAllowedMethods());
}

public function testFailureResultProcessedAsMiddlewareDelegatesToHandler()
Expand Down

0 comments on commit 3b21fb4

Please sign in to comment.