Skip to content

Commit

Permalink
Remove dependency of Dispatcher in FastRouteDispatcher and PhrouteDis…
Browse files Browse the repository at this point in the history
…patcher
  • Loading branch information
rougin committed Feb 9, 2018
1 parent 26fc681 commit fb8e268
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/Routing/FastRouteDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @package Slytherin
* @author Rougin Royce Gutib <rougingutib@gmail.com>
*/
class FastRouteDispatcher extends Dispatcher implements DispatcherInterface
class FastRouteDispatcher implements DispatcherInterface
{
/**
* @var \FastRoute\Dispatcher
Expand Down Expand Up @@ -84,4 +84,25 @@ public function router(RouterInterface $router)

return $this;
}

/**
* Checks if the specified method is a valid HTTP method.
*
* @param string $httpMethod
* @return boolean
*
* @throws UnexpectedValueException
*/
protected function allowed($httpMethod)
{
$allowed = array('DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT');

if (in_array($httpMethod, $allowed) === false) {
$message = 'Used method is not allowed';

throw new \UnexpectedValueException($message);
}

return true;
}
}
23 changes: 22 additions & 1 deletion src/Routing/PhrouteDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @package Slytherin
* @author Rougin Royce Gutib <rougingutib@gmail.com>
*/
class PhrouteDispatcher extends Dispatcher implements DispatcherInterface
class PhrouteDispatcher implements DispatcherInterface
{
/**
* @var \Phroute\Phroute\Dispatcher
Expand Down Expand Up @@ -125,4 +125,25 @@ protected function exceptions(\Exception $exception, $uri)

throw new \UnexpectedValueException($message);
}

/**
* Checks if the specified method is a valid HTTP method.
*
* @param string $httpMethod
* @return boolean
*
* @throws UnexpectedValueException
*/
protected function allowed($httpMethod)
{
$allowed = array('DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT');

if (in_array($httpMethod, $allowed) === false) {
$message = 'Used method is not allowed';

throw new \UnexpectedValueException($message);
}

return true;
}
}

0 comments on commit fb8e268

Please sign in to comment.