Skip to content

Commit

Permalink
Fix issue when capturing routes with OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Jan 12, 2024
1 parent 072cb7f commit e3cd43a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Routing/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Dispatcher implements DispatcherInterface
/**
* @var string[]
*/
protected $allowed = array('DELETE', 'GET', 'PATCH', 'POST', 'PUT');
protected $allowed = array('DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT');

/**
* @var \Rougin\Slytherin\Routing\RouterInterface
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function validMethod($method)
{
if (in_array($method, $this->allowed)) return true;

$message = 'Used method is not allowed';
$message = 'Used method is not allowed (' . $method . ')';

throw new \BadMethodCallException($message);
}
Expand All @@ -125,7 +125,9 @@ protected function match($method, $uri)

$sameMethod = $route->getMethod() === $method;

if ($matched && $sameMethod)
$isOptions = $route->getMethod() === 'OPTIONS';

if ($matched && ($sameMethod || $isOptions))
{
return $route->setParams($matches);
}
Expand Down

0 comments on commit e3cd43a

Please sign in to comment.