mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 18:52:15 +00:00
Development
- Began work on new documentation. - BaseCsrfVerifier now only matches `POST`, `PUT` and `DELETE`. - Parameters are now parsed on custom regex-matches. - Added `$type` option to `get` method in `Input` class.
This commit is contained in:
@@ -189,11 +189,12 @@ class Input
|
|||||||
*
|
*
|
||||||
* @param string $index
|
* @param string $index
|
||||||
* @param string|null $default
|
* @param string|null $default
|
||||||
|
* @param string|null $method
|
||||||
* @return InputItem|string
|
* @return InputItem|string
|
||||||
*/
|
*/
|
||||||
public function get($index, $default = null)
|
public function get($index, $default = null, $method = null)
|
||||||
{
|
{
|
||||||
$input = $this->getObject($index, $default);
|
$input = $this->getObject($index, $default, $method);
|
||||||
|
|
||||||
if ($input instanceof InputItem) {
|
if ($input instanceof InputItem) {
|
||||||
return (trim($input->getValue()) === '') ? $default : $input->getValue();
|
return (trim($input->getValue()) === '') ? $default : $input->getValue();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class BaseCsrfVerifier implements IMiddleware
|
|||||||
$this->csrfToken = new CsrfToken();
|
$this->csrfToken = new CsrfToken();
|
||||||
|
|
||||||
// Generate or get the CSRF-Token from Cookie.
|
// Generate or get the CSRF-Token from Cookie.
|
||||||
$this->token = (!$this->hasToken()) ? $this->generateToken() : $this->csrfToken->getToken();
|
$this->token = ($this->hasToken() === false) ? $this->generateToken() : $this->csrfToken->getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +58,7 @@ class BaseCsrfVerifier implements IMiddleware
|
|||||||
public function handle(Request $request, ILoadableRoute &$route = null)
|
public function handle(Request $request, ILoadableRoute &$route = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($request->getMethod() !== 'get' && !$this->skip($request)) {
|
if (in_array($request->getMethod(), ['post', 'put', 'delete']) === true && $this->skip($request) === false) {
|
||||||
|
|
||||||
$token = $request->getInput()->get(static::POST_KEY, null, 'post');
|
$token = $request->getInput()->get(static::POST_KEY, null, 'post');
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class Request
|
|||||||
$this->parseHeaders();
|
$this->parseHeaders();
|
||||||
$this->host = $this->getHeader('http-host');;
|
$this->host = $this->getHeader('http-host');;
|
||||||
$this->uri = $this->getHeader('request-uri');
|
$this->uri = $this->getHeader('request-uri');
|
||||||
$this->method = strtolower($this->getHeader('request-method'));
|
$this->method = $this->input->get('_method', strtolower($this->getHeader('request-method')));
|
||||||
$this->input = new Input($this);
|
$this->input = new Input($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ class RouteUrl extends LoadableRoute
|
|||||||
// Match on custom defined regular expression
|
// Match on custom defined regular expression
|
||||||
if ($this->regex !== null) {
|
if ($this->regex !== null) {
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
if (preg_match('/(' . $this->regex . ')/is', $request->getHost() . $url, $parameters)) {
|
if (preg_match($this->regex, $request->getHost() . $url, $parameters)) {
|
||||||
$this->parameters = (array)$parameters[0];
|
/* Remove global match */
|
||||||
|
if(count($parameters) > 1) {
|
||||||
|
array_shift($parameters);
|
||||||
|
$this->parameters = $parameters;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user