mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 13:02:14 +00:00
[FEATURE] Added option to get/set the filterEmptyParams option on IRoute classes (as requested by: #453).
This commit is contained in:
@@ -22,8 +22,8 @@ interface IRoute
|
|||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Router $router
|
* @param Router $router
|
||||||
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
|
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
|
||||||
*/
|
*/
|
||||||
public function renderRoute(Request $request, Router $router): ?string;
|
public function renderRoute(Request $request, Router $router): ?string;
|
||||||
|
|
||||||
@@ -206,4 +206,18 @@ interface IRoute
|
|||||||
*/
|
*/
|
||||||
public function setMiddlewares(array $middlewares): self;
|
public function setMiddlewares(array $middlewares): self;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If enabled parameters containing null-value will not be passed along to the callback.
|
||||||
|
*
|
||||||
|
* @param bool $enabled
|
||||||
|
* @return static $this
|
||||||
|
*/
|
||||||
|
public function setFilterEmptyParams(bool $enabled): self;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status if filtering of empty params is enabled or disabled
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getFilterEmptyParams(): bool;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -77,6 +77,7 @@ abstract class Route implements IRoute
|
|||||||
$router->debug('Executing callback');
|
$router->debug('Executing callback');
|
||||||
|
|
||||||
/* When the callback is a function */
|
/* When the callback is a function */
|
||||||
|
|
||||||
return $router->getClassLoader()->loadClosure($callback, $parameters);
|
return $router->getClassLoader()->loadClosure($callback, $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +270,7 @@ abstract class Route implements IRoute
|
|||||||
|
|
||||||
public function getMethod(): ?string
|
public function getMethod(): ?string
|
||||||
{
|
{
|
||||||
if(\is_array($this->callback) === true && \count($this->callback) > 1) {
|
if (\is_array($this->callback) === true && \count($this->callback) > 1) {
|
||||||
return $this->callback[1];
|
return $this->callback[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,12 +285,13 @@ abstract class Route implements IRoute
|
|||||||
|
|
||||||
public function getClass(): ?string
|
public function getClass(): ?string
|
||||||
{
|
{
|
||||||
if(\is_array($this->callback) === true && \count($this->callback) > 0) {
|
if (\is_array($this->callback) === true && \count($this->callback) > 0) {
|
||||||
return $this->callback[0];
|
return $this->callback[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
|
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
|
||||||
$tmp = explode('@', $this->callback);
|
$tmp = explode('@', $this->callback);
|
||||||
|
|
||||||
return $tmp[0];
|
return $tmp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,12 +301,14 @@ abstract class Route implements IRoute
|
|||||||
public function setMethod(string $method): IRoute
|
public function setMethod(string $method): IRoute
|
||||||
{
|
{
|
||||||
$this->callback = [$this->getClass(), $method];
|
$this->callback = [$this->getClass(), $method];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setClass(string $class): IRoute
|
public function setClass(string $class): IRoute
|
||||||
{
|
{
|
||||||
$this->callback = [$class, $this->getMethod()];
|
$this->callback = [$class, $this->getMethod()];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,9 +443,9 @@ abstract class Route implements IRoute
|
|||||||
* Add regular expression parameter match.
|
* Add regular expression parameter match.
|
||||||
* Alias for LoadableRoute::where()
|
* Alias for LoadableRoute::where()
|
||||||
*
|
*
|
||||||
* @see LoadableRoute::where()
|
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return static
|
* @return static
|
||||||
|
* @see LoadableRoute::where()
|
||||||
*/
|
*/
|
||||||
public function where(array $options)
|
public function where(array $options)
|
||||||
{
|
{
|
||||||
@@ -489,9 +493,9 @@ abstract class Route implements IRoute
|
|||||||
/**
|
/**
|
||||||
* Add middleware class-name
|
* Add middleware class-name
|
||||||
*
|
*
|
||||||
* @deprecated This method is deprecated and will be removed in the near future.
|
|
||||||
* @param IMiddleware|string $middleware
|
* @param IMiddleware|string $middleware
|
||||||
* @return static
|
* @return static
|
||||||
|
* @deprecated This method is deprecated and will be removed in the near future.
|
||||||
*/
|
*/
|
||||||
public function setMiddleware($middleware)
|
public function setMiddleware($middleware)
|
||||||
{
|
{
|
||||||
@@ -558,4 +562,25 @@ abstract class Route implements IRoute
|
|||||||
return $this->defaultParameterRegex;
|
return $this->defaultParameterRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If enabled parameters containing null-value will not be passed along to the callback.
|
||||||
|
*
|
||||||
|
* @param bool $enabled
|
||||||
|
* @return static $this
|
||||||
|
*/
|
||||||
|
public function setFilterEmptyParams(bool $enabled): IRoute
|
||||||
|
{
|
||||||
|
$this->filterEmptyParams = $enabled;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status if filtering of empty params is enabled or disabled
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getFilterEmptyParams(): bool
|
||||||
|
{
|
||||||
|
return $this->filterEmptyParams;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user