Files
simple-php-router/src/Pecee/SimpleRouter/RouterGroup.php
T
Simon Sessingø 58e4eb85bb [BUGFIX] Fixed method not allowed exception.
- Method request type are now checked on all classes in the RouterBase class.
2015-10-21 10:14:21 +02:00

39 lines
1002 B
PHP

<?php
namespace Pecee\SimpleRouter;
use Pecee\Http\Request;
class RouterGroup extends RouterEntry {
public function __construct() {
parent::__construct();
}
public function matchRoute(Request $request) {
// Check if request method is allowed
if(strtolower($request->getUri()) == strtolower($this->prefix) || stripos($request->getUri(), $this->prefix) === 0) {
$hasAccess = (!$this->method);
if($this->method) {
if(is_array($this->method)) {
$hasAccess = (in_array($request->getMethod(), $this->getRequestMethods()));
} else {
$hasAccess = strtolower($this->getRequestMethods()) == strtolower($request->getMethod());
}
}
if(!$hasAccess) {
throw new RouterException('Method not allowed');
}
return $this;
}
// No match here, move on...
return null;
}
}