mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-10 22:32:13 +00:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8923beeacf | |||
| 3534233a76 | |||
| 2a2152432a | |||
| 0f55480156 | |||
| 0b01aa9ba9 | |||
| 99ed44eb1e | |||
| 14c21998e9 | |||
| 565a926bd3 | |||
| d75af212e9 | |||
| 64483652ff | |||
| 3c03f08edf | |||
| d17ee96221 | |||
| ef4756c45b | |||
| ed1ed43484 | |||
| 36dda20bbe | |||
| a275366a90 | |||
| e22ea70047 | |||
| 4d1caddce4 | |||
| 0970bd00c6 | |||
| 49b132da93 | |||
| 08d78c8f71 | |||
| 5986dc9a08 | |||
| cdf165d0f4 | |||
| adfe70f191 | |||
| cd891d5334 | |||
| 7feb464af1 | |||
| 12b6e3c1ab | |||
| f085134ae3 | |||
| 8ffa1088ab | |||
| 9b8843aa08 | |||
| f565014dff | |||
| ad765b9856 | |||
| 97b61fb8bf | |||
| 847cb3e273 | |||
| 0ff9258776 | |||
| b937b610de | |||
| 5dc3e99d6e | |||
| fadb783d3c | |||
| 578fa10fc9 | |||
| 8477ea19d4 | |||
| 72ebada821 | |||
| 4121011ef2 | |||
| e5b5b0898f | |||
| 5dbfc3dbfe | |||
| 515fbc173c | |||
| 0aea8673d9 | |||
| 89b766ff2f | |||
| 9c66a4dfd8 | |||
| 0cb7fc416d | |||
| d5bf77cbd4 | |||
| 1e9fa9c6a1 | |||
| 0630569f56 |
@@ -1742,6 +1742,7 @@ SimpleRouter::setCustomClassLoader(new MyCustomClassLoader());
|
|||||||
php-di support was discontinued by version 4.3, however you can easily add it again by creating your own class-loader like the example below:
|
php-di support was discontinued by version 4.3, however you can easily add it again by creating your own class-loader like the example below:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
use Pecee\SimpleRouter\ClassLoader\IClassLoader;
|
||||||
use Pecee\SimpleRouter\Exceptions\ClassNotFoundHttpException;
|
use Pecee\SimpleRouter\Exceptions\ClassNotFoundHttpException;
|
||||||
|
|
||||||
class MyCustomClassLoader implements IClassLoader
|
class MyCustomClassLoader implements IClassLoader
|
||||||
@@ -1762,19 +1763,14 @@ class MyCustomClassLoader implements IClassLoader
|
|||||||
*
|
*
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return object
|
* @return object
|
||||||
* @throws NotFoundHttpException
|
* @throws ClassNotFoundHttpException
|
||||||
*/
|
*/
|
||||||
public function loadClass(string $class)
|
public function loadClass(string $class)
|
||||||
{
|
{
|
||||||
if (class_exists($class) === false) {
|
if ($this->container->has($class) === false) {
|
||||||
throw new NotFoundHttpException(sprintf('Class "%s" does not exist', $class), 404);
|
throw new ClassNotFoundHttpException($class, null, sprintf('Class "%s" does not exist', $class), 404, null);
|
||||||
}
|
}
|
||||||
|
return $this->container->get($class);
|
||||||
try {
|
|
||||||
return $this->container->get($class);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1782,15 +1778,11 @@ class MyCustomClassLoader implements IClassLoader
|
|||||||
* @param object $class
|
* @param object $class
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @return object
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function loadClassMethod($class, string $method, array $parameters)
|
public function loadClassMethod($class, string $method, array $parameters)
|
||||||
{
|
{
|
||||||
try {
|
return (string)$this->container->call([$class, $method], $parameters);
|
||||||
return $this->container->call([$class, $method], $parameters);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1798,15 +1790,11 @@ class MyCustomClassLoader implements IClassLoader
|
|||||||
*
|
*
|
||||||
* @param Callable $closure
|
* @param Callable $closure
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @return mixed
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function loadClosure(callable $closure, array $parameters)
|
public function loadClosure(callable $closure, array $parameters)
|
||||||
{
|
{
|
||||||
try {
|
return (string)$this->container->call($closure, $parameters);
|
||||||
return $this->container->call($closure, $parameters);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new NotFoundHttpException($e->getMessage(), (int)$e->getCode(), $e->getPrevious());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ class InputHandler
|
|||||||
if ($post !== false) {
|
if ($post !== false) {
|
||||||
$this->originalPost += $post;
|
$this->originalPost += $post;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$post = [];
|
||||||
|
parse_str($contents, $post);
|
||||||
|
$this->originalPost += $post;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +112,7 @@ class InputHandler
|
|||||||
foreach ($files as $key => $value) {
|
foreach ($files as $key => $value) {
|
||||||
|
|
||||||
// Parse multi dept file array
|
// Parse multi dept file array
|
||||||
if(isset($value['name']) === false && is_array($value) === true) {
|
if (isset($value['name']) === false && is_array($value) === true) {
|
||||||
$list[$key] = $this->parseFiles($value, $key);
|
$list[$key] = $this->parseFiles($value, $key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -161,12 +165,12 @@ class InputHandler
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
$file = InputFile::createFromArray([
|
$file = InputFile::createFromArray([
|
||||||
'index' => ($key === '' && $originalIndex !== '') ? $originalIndex : $key,
|
'index' => ($key === '' && $originalIndex !== '') ? $originalIndex : $key,
|
||||||
'name' => $original['name'][$key],
|
'name' => $original['name'][$key],
|
||||||
'error' => $original['error'][$key],
|
'error' => $original['error'][$key],
|
||||||
'tmp_name' => $original['tmp_name'][$key],
|
'tmp_name' => $original['tmp_name'][$key],
|
||||||
'type' => $original['type'][$key],
|
'type' => $original['type'][$key],
|
||||||
'size' => $original['size'][$key],
|
'size' => $original['size'][$key],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isset($output[$key]) === true) {
|
if (isset($output[$key]) === true) {
|
||||||
@@ -231,7 +235,7 @@ class InputHandler
|
|||||||
{
|
{
|
||||||
$element = null;
|
$element = null;
|
||||||
|
|
||||||
if(count($methods) > 0) {
|
if (count($methods) > 0) {
|
||||||
$methods = is_array(...$methods) ? array_values(...$methods) : $methods;
|
$methods = is_array(...$methods) ? array_values(...$methods) : $methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,9 +307,9 @@ class InputHandler
|
|||||||
public function exists($index, ...$methods): bool
|
public function exists($index, ...$methods): bool
|
||||||
{
|
{
|
||||||
// Check array
|
// Check array
|
||||||
if(is_array($index) === true) {
|
if (is_array($index) === true) {
|
||||||
foreach($index as $key) {
|
foreach ($index as $key) {
|
||||||
if($this->value($key, null, ...$methods) === null) {
|
if ($this->value($key, null, ...$methods) === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class BaseCsrfVerifier implements IMiddleware
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request): void
|
public function handle(Request $request): void
|
||||||
{
|
{
|
||||||
if ($this->skip($request) === false && ($request->isPostBack() === true || $this->isIncluded($request) === true)) {
|
if ($this->skip($request) === false && ($request->isPostBack() === true || $request->isPostBack() === true && $this->isIncluded($request) === true)) {
|
||||||
|
|
||||||
$token = $request->getInputHandler()->value(
|
$token = $request->getInputHandler()->value(
|
||||||
static::POST_KEY,
|
static::POST_KEY,
|
||||||
|
|||||||
+13
-12
@@ -130,9 +130,9 @@ class Request
|
|||||||
|
|
||||||
// Check if special IIS header exist, otherwise use default.
|
// Check if special IIS header exist, otherwise use default.
|
||||||
$url = $this->getHeader('unencoded-url');
|
$url = $this->getHeader('unencoded-url');
|
||||||
if($url !== null){
|
if ($url !== null) {
|
||||||
$this->setUrl(new Url($url));
|
$this->setUrl(new Url($url));
|
||||||
}else{
|
} else {
|
||||||
$this->setUrl(new Url(urldecode((string)$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'));
|
||||||
@@ -225,7 +225,7 @@ class Request
|
|||||||
public function getIp(bool $safeMode = false): ?string
|
public function getIp(bool $safeMode = false): ?string
|
||||||
{
|
{
|
||||||
$headers = [];
|
$headers = [];
|
||||||
if($safeMode === false) {
|
if ($safeMode === false) {
|
||||||
$headers = [
|
$headers = [
|
||||||
'http-cf-connecting-ip',
|
'http-cf-connecting-ip',
|
||||||
'http-client-ip',
|
'http-client-ip',
|
||||||
@@ -303,9 +303,9 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function getFirstHeader(array $headers, $defaultValue = null)
|
public function getFirstHeader(array $headers, $defaultValue = null)
|
||||||
{
|
{
|
||||||
foreach($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
$header = $this->getHeader($header);
|
$header = $this->getHeader($header);
|
||||||
if($header !== null) {
|
if ($header !== null) {
|
||||||
return $header;
|
return $header;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +329,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
protected function setContentType(string $contentType): self
|
protected function setContentType(string $contentType): self
|
||||||
{
|
{
|
||||||
if(strpos($contentType, ';') > 0) {
|
if (strpos($contentType, ';') > 0) {
|
||||||
$this->contentType = strtolower(substr($contentType, 0, strpos($contentType, ';')));
|
$this->contentType = strtolower(substr($contentType, 0, strpos($contentType, ';')));
|
||||||
} else {
|
} else {
|
||||||
$this->contentType = strtolower($contentType);
|
$this->contentType = strtolower($contentType);
|
||||||
@@ -371,7 +371,7 @@ class Request
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true when request-method is type that could contain data in the page body.
|
* Returns true when request-method is type that could contain data in the page body.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isPostBack(): bool
|
public function isPostBack(): bool
|
||||||
@@ -395,11 +395,7 @@ class Request
|
|||||||
{
|
{
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
|
|
||||||
if ($this->url->getHost() === null) {
|
if ($this->isSecure() === true) {
|
||||||
$this->url->setHost((string)$this->getHost());
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->isSecure() === true) {
|
|
||||||
$this->url->setScheme('https');
|
$this->url->setScheme('https');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,6 +405,11 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function setHost(?string $host): void
|
public function setHost(?string $host): void
|
||||||
{
|
{
|
||||||
|
// Strip any potential ports from hostname
|
||||||
|
if (strpos((string)$host, ':') !== false) {
|
||||||
|
$host = strstr($host, strrchr($host, ':'), true);
|
||||||
|
}
|
||||||
|
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ class Response
|
|||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param ?int $httpCode
|
* @param ?int $httpCode
|
||||||
|
*
|
||||||
|
* @return never
|
||||||
*/
|
*/
|
||||||
public function redirect(string $url, ?int $httpCode = null): void
|
public function redirect(string $url, ?int $httpCode = null): void
|
||||||
{
|
{
|
||||||
@@ -127,4 +129,4 @@ class Response
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-4
@@ -67,7 +67,11 @@ class Url implements JsonSerializable
|
|||||||
public function __construct(?string $url)
|
public function __construct(?string $url)
|
||||||
{
|
{
|
||||||
$this->originalUrl = $url;
|
$this->originalUrl = $url;
|
||||||
|
$this->parse($url, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(?string $url, bool $setOriginalPath = false): self
|
||||||
|
{
|
||||||
if ($url !== null && $url !== '/') {
|
if ($url !== null && $url !== '/') {
|
||||||
$data = $this->parseUrl($url);
|
$data = $this->parseUrl($url);
|
||||||
|
|
||||||
@@ -79,7 +83,10 @@ class Url implements JsonSerializable
|
|||||||
|
|
||||||
if (isset($data['path']) === true) {
|
if (isset($data['path']) === true) {
|
||||||
$this->setPath($data['path']);
|
$this->setPath($data['path']);
|
||||||
$this->originalPath = $data['path'];
|
|
||||||
|
if ($setOriginalPath === true) {
|
||||||
|
$this->originalPath = $data['path'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fragment = $data['fragment'] ?? null;
|
$this->fragment = $data['fragment'] ?? null;
|
||||||
@@ -88,6 +95,7 @@ class Url implements JsonSerializable
|
|||||||
$this->setQueryString($data['query']);
|
$this->setQueryString($data['query']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,10 +144,15 @@ class Url implements JsonSerializable
|
|||||||
/**
|
/**
|
||||||
* Get url host
|
* Get url host
|
||||||
*
|
*
|
||||||
|
* @param bool $includeTrails Prepend // in front of hostname
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getHost(): ?string
|
public function getHost(bool $includeTrails = false): ?string
|
||||||
{
|
{
|
||||||
|
if ((string)$this->host !== '' && $includeTrails === true) {
|
||||||
|
return '//' . $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->host;
|
return $this->host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,12 +535,12 @@ class Url implements JsonSerializable
|
|||||||
*/
|
*/
|
||||||
public function jsonSerialize(): string
|
public function jsonSerialize(): string
|
||||||
{
|
{
|
||||||
return $this->getRelativeUrl();
|
return $this->getHost(true) . $this->getRelativeUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return $this->getRelativeUrl();
|
return $this->getHost(true) . $this->getRelativeUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ use Pecee\Http\Middleware\IMiddleware;
|
|||||||
use Pecee\Http\Request;
|
use Pecee\Http\Request;
|
||||||
use Pecee\SimpleRouter\Exceptions\HttpException;
|
use Pecee\SimpleRouter\Exceptions\HttpException;
|
||||||
use Pecee\SimpleRouter\Router;
|
use Pecee\SimpleRouter\Router;
|
||||||
|
use Pecee\SimpleRouter\SimpleRouter;
|
||||||
|
|
||||||
abstract class LoadableRoute extends Route implements ILoadableRoute
|
abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||||
{
|
{
|
||||||
@@ -138,12 +139,6 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
{
|
{
|
||||||
$url = $this->getUrl();
|
$url = $this->getUrl();
|
||||||
|
|
||||||
$group = $this->getGroup();
|
|
||||||
|
|
||||||
if ($group !== null && count($group->getDomains()) !== 0) {
|
|
||||||
$url = '//' . $group->getDomains()[0] . $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the param string - {parameter} */
|
/* Create the param string - {parameter} */
|
||||||
$param1 = $this->paramModifiers[0] . '%s' . $this->paramModifiers[1];
|
$param1 = $this->paramModifiers[0] . '%s' . $this->paramModifiers[1];
|
||||||
|
|
||||||
@@ -177,7 +172,15 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtrim('/' . ltrim($url, '/'), '/') . '/';
|
$url = rtrim('/' . ltrim($url, '/'), '/') . '/';
|
||||||
|
|
||||||
|
$group = $this->getGroup();
|
||||||
|
|
||||||
|
if ($group !== null && count($group->getDomains()) !== 0 && SimpleRouter::request()->getHost() !== $group->getDomains()[0]) {
|
||||||
|
$url = '//' . $group->getDomains()[0] . $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Pecee\SimpleRouter\Route;
|
namespace Pecee\SimpleRouter\Route;
|
||||||
|
|
||||||
use Pecee\Http\Request;
|
use Pecee\Http\Request;
|
||||||
|
use Pecee\SimpleRouter\SimpleRouter;
|
||||||
|
|
||||||
class RouteController extends LoadableRoute implements IControllerRoute
|
class RouteController extends LoadableRoute implements IControllerRoute
|
||||||
{
|
{
|
||||||
@@ -77,13 +78,15 @@ class RouteController extends LoadableRoute implements IControllerRoute
|
|||||||
|
|
||||||
$group = $this->getGroup();
|
$group = $this->getGroup();
|
||||||
|
|
||||||
if ($group !== null && count($group->getDomains()) !== 0) {
|
|
||||||
$url .= '//' . $group->getDomains()[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$url .= '/' . trim($this->getUrl(), '/') . '/' . strtolower((string)$method) . implode('/', $parameters);
|
$url .= '/' . trim($this->getUrl(), '/') . '/' . strtolower((string)$method) . implode('/', $parameters);
|
||||||
|
|
||||||
return '/' . trim($url, '/') . '/';
|
$url = '/' . trim($url, '/') . '/';
|
||||||
|
|
||||||
|
if ($group !== null && count($group->getDomains()) !== 0 && SimpleRouter::request()->getHost() !== $group->getDomains()[0]) {
|
||||||
|
$url = '//' . $group->getDomains()[0] . $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function matchRoute(string $url, Request $request): bool
|
public function matchRoute(string $url, Request $request): bool
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ class RouteGroup extends Route implements IGroupRoute
|
|||||||
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
|
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($merge === false && isset($settings['domain']) === true) {
|
if (isset($settings['domain']) === true) {
|
||||||
$this->setDomains((array)$settings['domain']);
|
$this->setDomains((array)$settings['domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Pecee\SimpleRouter\Route;
|
namespace Pecee\SimpleRouter\Route;
|
||||||
|
|
||||||
use Pecee\Http\Request;
|
use Pecee\Http\Request;
|
||||||
|
use Pecee\SimpleRouter\SimpleRouter;
|
||||||
|
|
||||||
class RouteResource extends LoadableRoute implements IControllerRoute
|
class RouteResource extends LoadableRoute implements IControllerRoute
|
||||||
{
|
{
|
||||||
@@ -80,7 +81,14 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
|||||||
return rtrim($this->url . $parametersUrl . $this->urls[$url], '/') . '/';
|
return rtrim($this->url . $parametersUrl . $this->urls[$url], '/') . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->url . $parametersUrl;
|
$url = $this->url . $parametersUrl;
|
||||||
|
|
||||||
|
$group = $this->getGroup();
|
||||||
|
if ($group !== null && count($group->getDomains()) !== 0 && SimpleRouter::request()->getHost() !== $group->getDomains()[0]) {
|
||||||
|
$url = '//' . $group->getDomains()[0] . $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function call($method): bool
|
protected function call($method): bool
|
||||||
|
|||||||
@@ -690,10 +690,7 @@ class Router
|
|||||||
|
|
||||||
/* If nothing is defined and a route is loaded we use that */
|
/* If nothing is defined and a route is loaded we use that */
|
||||||
if ($name === null && $loadedRoute !== null) {
|
if ($name === null && $loadedRoute !== null) {
|
||||||
return $this->request
|
return $this->request->getUrlCopy()->parse($loadedRoute->findUrl($loadedRoute->getMethod(), $parameters, $name))->setParams($getParams);
|
||||||
->getUrlCopy()
|
|
||||||
->setPath($loadedRoute->findUrl($loadedRoute->getMethod(), $parameters, $name))
|
|
||||||
->setParams($getParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($name !== null) {
|
if ($name !== null) {
|
||||||
@@ -701,10 +698,7 @@ class Router
|
|||||||
$route = $this->findRoute($name);
|
$route = $this->findRoute($name);
|
||||||
|
|
||||||
if ($route !== null) {
|
if ($route !== null) {
|
||||||
return $this->request
|
return $this->request->getUrlCopy()->parse($route->findUrl($route->getMethod(), $parameters, $name))->setParams($getParams);
|
||||||
->getUrlCopy()
|
|
||||||
->setPath($route->findUrl($route->getMethod(), $parameters, $name))
|
|
||||||
->setParams($getParams);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,18 +713,12 @@ class Router
|
|||||||
|
|
||||||
/* Check if the route contains the name/alias */
|
/* Check if the route contains the name/alias */
|
||||||
if ($processedRoute->hasName($controller) === true) {
|
if ($processedRoute->hasName($controller) === true) {
|
||||||
return $this->request
|
return $this->request->getUrlCopy()->parse($processedRoute->findUrl($method, $parameters, $name))->setParams($getParams);
|
||||||
->getUrlCopy()
|
|
||||||
->setPath($processedRoute->findUrl($method, $parameters, $name))
|
|
||||||
->setParams($getParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the route controller is equal to the name */
|
/* Check if the route controller is equal to the name */
|
||||||
if ($processedRoute instanceof IControllerRoute && strtolower($processedRoute->getController()) === strtolower($controller)) {
|
if ($processedRoute instanceof IControllerRoute && strtolower($processedRoute->getController()) === strtolower($controller)) {
|
||||||
return $this->request
|
return $this->request->getUrlCopy()->parse($processedRoute->findUrl($method, $parameters, $name))->setParams($getParams);
|
||||||
->getUrlCopy()
|
|
||||||
->setPath($processedRoute->findUrl($method, $parameters, $name))
|
|
||||||
->setParams($getParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -740,10 +728,7 @@ class Router
|
|||||||
$url = trim(implode('/', array_merge((array)$name, (array)$parameters)), '/');
|
$url = trim(implode('/', array_merge((array)$name, (array)$parameters)), '/');
|
||||||
$url = (($url === '') ? '/' : '/' . $url . '/');
|
$url = (($url === '') ? '/' : '/' . $url . '/');
|
||||||
|
|
||||||
return $this->request
|
return $this->request->getUrlCopy()->parse($url)->setParams($getParams);
|
||||||
->getUrlCopy()
|
|
||||||
->setPath($url)
|
|
||||||
->setParams($getParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -973,4 +958,4 @@ class Router
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -94,11 +94,13 @@ class RouterUrlTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
public function testSimilarUrls()
|
public function testSimilarUrls()
|
||||||
{
|
{
|
||||||
|
TestRouter::reset();
|
||||||
// Match normal route on alias
|
// Match normal route on alias
|
||||||
TestRouter::get('/url11', 'DummyController@method1');
|
TestRouter::get('/url11', 'DummyController@method1');
|
||||||
TestRouter::get('/url22', 'DummyController@method2');
|
TestRouter::get('/url22', 'DummyController@method2');
|
||||||
TestRouter::get('/url33', 'DummyController@method2')->name('match');
|
TestRouter::get('/url33', 'DummyController@method2')->name('match');
|
||||||
|
|
||||||
|
|
||||||
TestRouter::debugNoReset('/url33', 'get');
|
TestRouter::debugNoReset('/url33', 'get');
|
||||||
|
|
||||||
$this->assertEquals(TestRouter::getUrl('match'), TestRouter::getUrl());
|
$this->assertEquals(TestRouter::getUrl('match'), TestRouter::getUrl());
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
|
|||||||
{
|
{
|
||||||
$request = static::request();
|
$request = static::request();
|
||||||
|
|
||||||
$request->setUrl((new \Pecee\Http\Url($testUrl))->setHost('local.unitTest'));
|
$request->setUrl((new \Pecee\Http\Url($testUrl)));
|
||||||
$request->setMethod($testMethod);
|
$request->setMethod($testMethod);
|
||||||
|
|
||||||
static::start();
|
static::start();
|
||||||
|
|||||||
Reference in New Issue
Block a user