mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 16:57:53 +00:00
@@ -17,10 +17,10 @@ jobs:
|
|||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
php-version:
|
php-version:
|
||||||
- 7.1
|
|
||||||
- 7.4
|
- 7.4
|
||||||
|
- 8.0
|
||||||
phpunit-version:
|
phpunit-version:
|
||||||
- 7.5.20
|
- 8.5.32
|
||||||
dependencies:
|
dependencies:
|
||||||
- lowest
|
- lowest
|
||||||
- highest
|
- highest
|
||||||
|
|||||||
+6
-1
@@ -31,7 +31,7 @@
|
|||||||
"ext-json": "*"
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^7",
|
"phpunit/phpunit": "^8",
|
||||||
"mockery/mockery": "^1",
|
"mockery/mockery": "^1",
|
||||||
"phpstan/phpstan": "^0",
|
"phpstan/phpstan": "^0",
|
||||||
"phpstan/phpstan-phpunit": "^0",
|
"phpstan/phpstan-phpunit": "^0",
|
||||||
@@ -47,5 +47,10 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Pecee\\": "src/Pecee/"
|
"Pecee\\": "src/Pecee/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"ocramius/package-versions": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ class Request
|
|||||||
if($url !== null){
|
if($url !== null){
|
||||||
$this->setUrl(new Url($url));
|
$this->setUrl(new Url($url));
|
||||||
}else{
|
}else{
|
||||||
$this->setUrl(new Url(urldecode($this->getHeader('request-uri'))));
|
$this->setUrl(new Url(urldecode((string)$this->getHeader('request-uri'))));
|
||||||
}
|
}
|
||||||
$this->setContentType((string)$this->getHeader('content-type'));
|
$this->setContentType((string)$this->getHeader('content-type'));
|
||||||
$this->setMethod((string)($_POST[static::FORCE_METHOD_KEY] ?? $this->getHeader('request-method')));
|
$this->setMethod((string)($_POST[static::FORCE_METHOD_KEY] ?? $this->getHeader('request-method')));
|
||||||
@@ -364,7 +364,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function isAjax(): bool
|
public function isAjax(): bool
|
||||||
{
|
{
|
||||||
return (strtolower($this->getHeader('http-x-requested-with')) === 'xmlhttprequest');
|
return (strtolower((string)$this->getHeader('http-x-requested-with')) === 'xmlhttprequest');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ class Response
|
|||||||
/**
|
/**
|
||||||
* Json encode
|
* Json encode
|
||||||
* @param array|JsonSerializable $value
|
* @param array|JsonSerializable $value
|
||||||
* @param ?int $options JSON options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR.
|
* @param int $options JSON options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR.
|
||||||
* @param int $dept JSON debt.
|
* @param int $dept JSON debt.
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function json($value, ?int $options = null, int $dept = 512): void
|
public function json($value, int $options = 0, int $dept = 512): void
|
||||||
{
|
{
|
||||||
if (($value instanceof JsonSerializable) === false && is_array($value) === false) {
|
if (($value instanceof JsonSerializable) === false && is_array($value) === false) {
|
||||||
throw new InvalidArgumentException('Invalid type for parameter "value". Must be of type array or object implementing the \JsonSerializable interface.');
|
throw new InvalidArgumentException('Invalid type for parameter "value". Must be of type array or object implementing the \JsonSerializable interface.');
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
|
|
||||||
if (stripos($url, $param1) !== false || stripos($url, $param) !== false) {
|
if (stripos($url, $param1) !== false || stripos($url, $param) !== false) {
|
||||||
/* Add parameter to the correct position */
|
/* Add parameter to the correct position */
|
||||||
$url = str_ireplace([sprintf($param1, $param), sprintf($param2, $param)], $value, $url);
|
$url = str_ireplace([sprintf($param1, $param), sprintf($param2, $param)], (string)$value, $url);
|
||||||
} else {
|
} else {
|
||||||
/* Parameter aren't recognized and will be appended at the end of the url */
|
/* Parameter aren't recognized and will be appended at the end of the url */
|
||||||
$url .= $value . '/';
|
$url .= $value . '/';
|
||||||
@@ -195,7 +195,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
*/
|
*/
|
||||||
public function hasName(string $name): bool
|
public function hasName(string $name): bool
|
||||||
{
|
{
|
||||||
return strtolower($this->name) === strtolower($name);
|
return strtolower((string)$this->name) === strtolower((string)$name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
|||||||
$url .= '//' . $group->getDomains()[0];
|
$url .= '//' . $group->getDomains()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$url .= '/' . trim($this->getUrl(), '/') . '/' . strtolower($method) . implode('/', $parameters);
|
$url .= '/' . trim($this->getUrl(), '/') . '/' . strtolower((string)$method) . implode('/', $parameters);
|
||||||
|
|
||||||
return '/' . trim($url, '/') . '/';
|
return '/' . trim($url, '/') . '/';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class RouteGroup extends Route implements IGroupRoute
|
|||||||
$parsedPrefix = $this->prefix;
|
$parsedPrefix = $this->prefix;
|
||||||
|
|
||||||
foreach ($this->getParameters() as $parameter => $value) {
|
foreach ($this->getParameters() as $parameter => $value) {
|
||||||
$parsedPrefix = str_ireplace('{' . $parameter . '}', $value, $parsedPrefix);
|
$parsedPrefix = str_ireplace('{' . $parameter . '}', (string)$value, (string)$parsedPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip if prefix doesn't match */
|
/* Skip if prefix doesn't match */
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$action = strtolower(trim($this->parameters['action']));
|
$action = strtolower(trim((string)$this->parameters['action']));
|
||||||
$id = $this->parameters['id'];
|
$id = $this->parameters['id'];
|
||||||
|
|
||||||
// Remove action parameter
|
// Remove action parameter
|
||||||
|
|||||||
@@ -608,7 +608,7 @@ class Router
|
|||||||
if (strpos($name, '@') !== false) {
|
if (strpos($name, '@') !== false) {
|
||||||
[$controller, $method] = array_map('strtolower', explode('@', $name));
|
[$controller, $method] = array_map('strtolower', explode('@', $name));
|
||||||
|
|
||||||
if ($controller === strtolower($route->getClass()) && $method === strtolower($route->getMethod())) {
|
if ($controller === strtolower((string)$route->getClass()) && $method === strtolower((string)$route->getMethod())) {
|
||||||
$this->debug('Found route "%s" by controller "%s" and method "%s"', $route->getUrl(), $controller, $method);
|
$this->debug('Found route "%s" by controller "%s" and method "%s"', $route->getUrl(), $controller, $method);
|
||||||
|
|
||||||
return $route;
|
return $route;
|
||||||
|
|||||||
Reference in New Issue
Block a user