Skip to content

Commit 363338c

Browse files
committed
Merge pull request #25 from skipperbent/development
Development
2 parents 933f237 + 3dd9dba commit 363338c

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

src/Pecee/Http/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct() {
2727
$this->host = $_SERVER['HTTP_HOST'];
2828
$this->uri = $_SERVER['REQUEST_URI'];
2929
$this->method = (isset($_POST['_method'])) ? strtolower($_POST['_method']) : strtolower($_SERVER['REQUEST_METHOD']);
30-
$this->headers = getallheaders();
30+
$this->headers = array_change_key_case(getallheaders(), CASE_LOWER);
3131
}
3232

3333
/**
@@ -105,7 +105,7 @@ public function getUserAgent() {
105105
* @return string|null
106106
*/
107107
public function getHeader($name) {
108-
return (isset($this->headers[$name])) ? $this->headers[$name] : null;
108+
return (isset($this->headers[strtolower($name)])) ? $this->headers[strtolower($name)] : null;
109109
}
110110

111111
/**

src/Pecee/SimpleRouter/RouterBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected function processRoutes(array $routes, array $settings = array(), array
5858

5959
$newPrefixes = $prefixes;
6060
$mergedSettings = array_merge($settings, $route->getMergeableSettings());
61+
6162
if($route->getPrefix()) {
6263
array_push($newPrefixes, rtrim($route->getPrefix(), '/'));
6364
}

src/Pecee/SimpleRouter/RouterEntry.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ abstract class RouterEntry {
1010
const REQUEST_TYPE_POST = 'post';
1111
const REQUEST_TYPE_GET = 'get';
1212
const REQUEST_TYPE_PUT = 'put';
13+
const REQUEST_TYPE_PATCH = 'patch';
1314
const REQUEST_TYPE_DELETE = 'delete';
1415

1516
public static $allowedRequestTypes = array(
1617
self::REQUEST_TYPE_DELETE,
1718
self::REQUEST_TYPE_GET,
1819
self::REQUEST_TYPE_POST,
19-
self::REQUEST_TYPE_PUT
20+
self::REQUEST_TYPE_PUT,
21+
self::REQUEST_TYPE_PATCH
2022
);
2123

2224
protected $settings;
2325
protected $callback;
2426
protected $parameters;
25-
protected $parametersRegex;
26-
protected $regexMatch;
2727

2828
public function __construct() {
2929
$this->settings = array();
3030
$this->settings['requestMethods'] = array();
31+
$this->settings['parametersRegex'] = array();
3132
$this->parameters = array();
32-
$this->parametersRegex = array();
3333
}
3434

3535
/**
@@ -245,13 +245,25 @@ protected function loadClass($name) {
245245

246246
public function loadMiddleware(Request $request) {
247247
if($this->getMiddleware()) {
248-
$middleware = $this->loadClass($this->getMiddleware());
249-
if (!($middleware instanceof IMiddleware)) {
250-
throw new RouterException($this->getMiddleware() . ' must be instance of Middleware');
248+
if(is_array($this->getMiddleware())) {
249+
foreach($this->getMiddleware() as $middleware) {
250+
$middleware = $this->loadClass($middleware);
251+
if (!($middleware instanceof IMiddleware)) {
252+
throw new RouterException($middleware . ' must be instance of Middleware');
253+
}
254+
255+
/* @var $class Middleware */
256+
$middleware->handle($request);
257+
}
258+
} else {
259+
$middleware = $this->loadClass($this->getMiddleware());
260+
if (!($middleware instanceof IMiddleware)) {
261+
throw new RouterException($this->getMiddleware() . ' must be instance of Middleware');
262+
}
263+
264+
/* @var $class Middleware */
265+
$middleware->handle($request);
251266
}
252-
253-
/* @var $class Middleware */
254-
$middleware->handle($request);
255267
}
256268
}
257269

src/Pecee/SimpleRouter/SimpleRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function post($url, $callback, array $settings = null) {
5757
public static function put($url, $callback, array $settings = null) {
5858
$route = new RouterRoute($url, $callback);
5959
$route->addSettings($settings);
60-
$route->setRequestMethods(array(RouterRoute::REQUEST_TYPE_PUT));
60+
$route->setRequestMethods(array(RouterRoute::REQUEST_TYPE_PUT, RouterRoute::REQUEST_TYPE_PATCH));
6161

6262
$router = RouterBase::getInstance();
6363
$router->addRoute($route);

0 commit comments

Comments
 (0)