Added support for PHP7

This commit is contained in:
Simon Sessingø
2018-03-20 03:38:55 +01:00
parent d279d5598d
commit f23d569757
58 changed files with 678 additions and 532 deletions
@@ -1,4 +1,5 @@
<?php
namespace Pecee\SimpleRouter\Route;
interface IControllerRoute extends IRoute
@@ -8,7 +9,7 @@ interface IControllerRoute extends IRoute
*
* @return string
*/
public function getController();
public function getController(): string;
/**
* Set controller class-name
@@ -16,21 +17,6 @@ interface IControllerRoute extends IRoute
* @param string $controller
* @return static
*/
public function setController($controller);
/**
* Return active method
*
* @return string
*/
public function getMethod();
/**
* Set active method
*
* @param string $method
* @return static
*/
public function setMethod($method);
public function setController($controller): self;
}
+9 -9
View File
@@ -13,7 +13,7 @@ interface IGroupRoute extends IRoute
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request);
public function matchDomain(Request $request): bool;
/**
* Add exception handler
@@ -36,35 +36,35 @@ interface IGroupRoute extends IRoute
*
* @return array
*/
public function getExceptionHandlers();
public function getExceptionHandlers(): array;
/**
* Get domains for domain.
*
* @return array
*/
public function getDomains();
public function getDomains(): array;
/**
* Set allowed domains for group.
*
* @param array $domains
* @return $this
* @return static
*/
public function setDomains(array $domains);
public function setDomains(array $domains): self;
/**
* Set prefix that child-routes will inherit.
*
* @param string $prefix
* @return string
* @return static
*/
public function setPrefix($prefix);
public function setPrefix($prefix): self;
/**
* Get prefix.
*
* @return string
* @return string|null
*/
public function getPrefix();
public function getPrefix(): ?string;
}
@@ -1,4 +1,5 @@
<?php
namespace Pecee\SimpleRouter\Route;
use Pecee\Http\Request;
@@ -14,7 +15,7 @@ interface ILoadableRoute extends IRoute
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null);
public function findUrl($method = null, $parameters = null, $name = null): string;
/**
* Loads and renders middlewares-classes
@@ -30,9 +31,9 @@ interface ILoadableRoute extends IRoute
/**
* Returns the provided name for the router.
*
* @return string
* @return string|null
*/
public function getName();
public function getName(): string;
/**
* Check if route has given name.
@@ -40,22 +41,22 @@ interface ILoadableRoute extends IRoute
* @param string $name
* @return bool
*/
public function hasName($name);
public function hasName($name): bool;
/**
* Sets the router name, which makes it easier to obtain the url or router at a later point.
*
* @param string $name
* @return static $this
* @return static
*/
public function setName($name);
public function setName($name): self;
/**
* Get regular expression match used for matching route (if defined).
*
* @return string
*/
public function getMatch();
public function getMatch(): string;
/**
* Add regular expression match for the entire route.
@@ -63,6 +64,6 @@ interface ILoadableRoute extends IRoute
* @param string $regex
* @return static
*/
public function setMatch($regex);
public function setMatch($regex): self;
}
+39 -28
View File
@@ -13,7 +13,7 @@ interface IRoute
* @param Request $request
* @return bool
*/
public function matchRoute($route, Request $request);
public function matchRoute($route, Request $request): bool;
/**
* Called when route is matched.
@@ -23,7 +23,7 @@ interface IRoute
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
* @return string
*/
public function renderRoute(Request $request);
public function renderRoute(Request $request): ?string;
/**
* Returns callback name/identifier for the current route based on the callback.
@@ -32,50 +32,50 @@ interface IRoute
*
* @return string
*/
public function getIdentifier();
public function getIdentifier(): string;
/**
* Set allowed request methods
*
* @param array $methods
* @return static $this
* @return static
*/
public function setRequestMethods(array $methods);
public function setRequestMethods(array $methods): self;
/**
* Get allowed request methods
*
* @return array
*/
public function getRequestMethods();
public function getRequestMethods(): array;
/**
* @return IRoute|null
*/
public function getParent();
public function getParent(): ?IRoute;
/**
* Get the group for the route.
*
* @return IGroupRoute|null
*/
public function getGroup();
public function getGroup(): ?IGroupRoute;
/**
* Set group
*
* @param IGroupRoute $group
* @return static $this
* @return static
*/
public function setGroup(IGroupRoute $group);
public function setGroup(IGroupRoute $group): self;
/**
* Set parent route
*
* @param IRoute $parent
* @return static $this
* @return static
*/
public function setParent(IRoute $parent);
public function setParent(IRoute $parent): self;
/**
* Set callback
@@ -83,33 +83,44 @@ interface IRoute
* @param string $callback
* @return static
*/
public function setCallback($callback);
public function setCallback($callback): self;
/**
* @return string
* @return string|callable
*/
public function getCallback();
public function getMethod();
/**
* Return active method
*
* @return string|null
*/
public function getMethod(): ?string;
/**
* Set active method
*
* @param string $method
* @return static
*/
public function setMethod($method): self;
public function getClass();
public function setMethod($method);
/**
* @param string $namespace
* @return static $this
* @return static
*/
public function setNamespace($namespace);
/**
* @return string
* @return string|null
*/
public function getNamespace();
public function getNamespace(): ?string;
/**
* @param string $namespace
* @return static $this
* @return static
*/
public function setDefaultNamespace($namespace);
@@ -120,7 +131,7 @@ interface IRoute
*
* @return array
*/
public function getWhere();
public function getWhere(): array;
/**
* Set parameter names.
@@ -135,7 +146,7 @@ interface IRoute
*
* @return array
*/
public function getParameters();
public function getParameters(): array;
/**
* Get parameters
@@ -159,14 +170,14 @@ interface IRoute
*
* @return array
*/
public function toArray();
public function toArray(): array;
/**
* Get middlewares array
*
* @return array
*/
public function getMiddlewares();
public function getMiddlewares(): array;
/**
* Set middleware class-name
@@ -174,14 +185,14 @@ interface IRoute
* @param string $middleware
* @return static
*/
public function addMiddleware($middleware);
public function addMiddleware($middleware): self;
/**
* Set middlewares array
*
* @param array $middlewares
* @return $this
* @return static
*/
public function setMiddlewares(array $middlewares);
public function setMiddlewares(array $middlewares): self;
}
+17 -17
View File
@@ -26,11 +26,11 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param Request $request
* @throws HttpException
*/
public function loadMiddleware(Request $request)
public function loadMiddleware(Request $request) : void
{
foreach ($this->getMiddlewares() as $middleware) {
if (is_object($middleware) === false) {
if (\is_object($middleware) === false) {
$middleware = $this->loadClass($middleware);
}
@@ -42,7 +42,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
}
}
public function matchRegex(Request $request, $url)
public function matchRegex(Request $request, $url) : ?bool
{
/* Match on custom defined regular expression */
@@ -59,7 +59,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $url
* @return static
*/
public function setUrl($url)
public function setUrl($url) : self
{
$this->url = ($url === '/') ? '/' : '/' . trim($url, '/') . '/';
@@ -75,7 +75,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
return $this;
}
public function getUrl()
public function getUrl() : string
{
return $this->url;
}
@@ -89,13 +89,13 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null)
public function findUrl($method = null, $parameters = null, $name = null) : string
{
$url = $this->getUrl();
$group = $this->getGroup();
if ($group !== null && count($group->getDomains()) !== 0) {
if ($group !== null && \count($group->getDomains()) !== 0) {
$url = '//' . $group->getDomains()[0] . $url;
}
@@ -114,7 +114,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
foreach (array_keys($params) as $param) {
if ($parameters === '' || (is_array($parameters) === true && count($parameters) === 0)) {
if ($parameters === '' || (\is_array($parameters) === true && \count($parameters) === 0)) {
$value = '';
} else {
$p = (array)$parameters;
@@ -144,7 +144,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
*
* @return string
*/
public function getName()
public function getName() : string
{
return $this->name;
}
@@ -155,9 +155,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $name
* @return bool
*/
public function hasName($name)
public function hasName($name) : bool
{
return (strtolower($this->name) === strtolower($name));
return strtolower($this->name) === strtolower($name);
}
/**
@@ -166,7 +166,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $regex
* @return static
*/
public function setMatch($regex)
public function setMatch($regex) : ILoadableRoute
{
$this->regex = $regex;
@@ -178,7 +178,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
*
* @return string
*/
public function getMatch()
public function getMatch() : string
{
return $this->regex;
}
@@ -191,7 +191,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string|array $name
* @return static
*/
public function name($name)
public function name($name) : ILoadableRoute
{
return $this->setName($name);
}
@@ -200,9 +200,9 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* Sets the router name, which makes it easier to obtain the url or router at a later point.
*
* @param string $name
* @return static $this
* @return static
*/
public function setName($name)
public function setName($name) : ILoadableRoute
{
$this->name = $name;
@@ -216,7 +216,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, $merge = false): IRoute
{
if (isset($values['as']) === true) {
+48 -48
View File
@@ -8,15 +8,15 @@ use Pecee\SimpleRouter\Exceptions\NotFoundHttpException;
abstract class Route implements IRoute
{
const PARAMETERS_REGEX_FORMAT = '%s([\w]+)(\%s?)%s';
const PARAMETERS_DEFAULT_REGEX = '[\w]+';
protected const PARAMETERS_REGEX_FORMAT = '%s([\w]+)(\%s?)%s';
protected const PARAMETERS_DEFAULT_REGEX = '[\w]+';
const REQUEST_TYPE_GET = 'get';
const REQUEST_TYPE_POST = 'post';
const REQUEST_TYPE_PUT = 'put';
const REQUEST_TYPE_PATCH = 'patch';
const REQUEST_TYPE_OPTIONS = 'options';
const REQUEST_TYPE_DELETE = 'delete';
public const REQUEST_TYPE_GET = 'get';
public const REQUEST_TYPE_POST = 'post';
public const REQUEST_TYPE_PUT = 'put';
public const REQUEST_TYPE_PATCH = 'patch';
public const REQUEST_TYPE_OPTIONS = 'options';
public const REQUEST_TYPE_DELETE = 'delete';
public static $requestTypes = [
self::REQUEST_TYPE_GET,
@@ -75,10 +75,10 @@ abstract class Route implements IRoute
* Render route
*
* @param Request $request
* @return string|mixed
* @return string|null
* @throws NotFoundHttpException
*/
public function renderRoute(Request $request)
public function renderRoute(Request $request): ?string
{
$callback = $this->getCallback();
@@ -97,9 +97,9 @@ abstract class Route implements IRoute
}
/* Render callback function */
if (is_callable($callback) === true) {
if (\is_callable($callback) === true) {
/* When the callback is a function */
return call_user_func_array($callback, $parameters);
return \call_user_func_array($callback, $parameters);
}
/* When the callback is a class + method */
@@ -116,7 +116,7 @@ abstract class Route implements IRoute
throw new NotFoundHttpException(sprintf('Method "%s" does not exist in class "%s"', $method, $className), 404);
}
return call_user_func_array([$class, $method], $parameters);
return \call_user_func_array([$class, $method], $parameters);
}
protected function parseParameters($route, $url, $parameterRegex = null)
@@ -138,7 +138,7 @@ abstract class Route implements IRoute
$regex = '';
if ($key < count($parameters[1])) {
if ($key < \count($parameters[1])) {
$name = $parameters[1][$key];
@@ -151,7 +151,7 @@ abstract class Route implements IRoute
if ($parameterRegex !== null) {
$regex = $parameterRegex;
} else {
$regex = ($this->defaultParameterRegex === null) ? static::PARAMETERS_DEFAULT_REGEX : $this->defaultParameterRegex;
$regex = $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
}
}
@@ -189,9 +189,9 @@ abstract class Route implements IRoute
*
* @return string
*/
public function getIdentifier()
public function getIdentifier(): string
{
if (is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
return $this->callback;
}
@@ -202,9 +202,9 @@ abstract class Route implements IRoute
* Set allowed request methods
*
* @param array $methods
* @return static $this
* @return static
*/
public function setRequestMethods(array $methods)
public function setRequestMethods(array $methods): IRoute
{
$this->requestMethods = $methods;
@@ -216,7 +216,7 @@ abstract class Route implements IRoute
*
* @return array
*/
public function getRequestMethods()
public function getRequestMethods(): array
{
return $this->requestMethods;
}
@@ -224,7 +224,7 @@ abstract class Route implements IRoute
/**
* @return IRoute|null
*/
public function getParent()
public function getParent(): ?IRoute
{
return $this->parent;
}
@@ -234,7 +234,7 @@ abstract class Route implements IRoute
*
* @return IGroupRoute|null
*/
public function getGroup()
public function getGroup(): ?IGroupRoute
{
return $this->group;
}
@@ -243,9 +243,9 @@ abstract class Route implements IRoute
* Set group
*
* @param IGroupRoute $group
* @return static $this
* @return static
*/
public function setGroup(IGroupRoute $group)
public function setGroup(IGroupRoute $group): IRoute
{
$this->group = $group;
@@ -259,9 +259,9 @@ abstract class Route implements IRoute
* Set parent route
*
* @param IRoute $parent
* @return static $this
* @return static
*/
public function setParent(IRoute $parent)
public function setParent(IRoute $parent): IRoute
{
$this->parent = $parent;
@@ -274,7 +274,7 @@ abstract class Route implements IRoute
* @param string $callback
* @return static
*/
public function setCallback($callback)
public function setCallback($callback): IRoute
{
$this->callback = $callback;
@@ -282,16 +282,16 @@ abstract class Route implements IRoute
}
/**
* @return string
* @return string|callable
*/
public function getCallback()
{
return $this->callback;
}
public function getMethod()
public function getMethod(): ?string
{
if (is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
$tmp = explode('@', $this->callback);
return $tmp[1];
@@ -302,7 +302,7 @@ abstract class Route implements IRoute
public function getClass()
{
if (is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
if (\is_string($this->callback) === true && strpos($this->callback, '@') !== false) {
$tmp = explode('@', $this->callback);
return $tmp[0];
@@ -311,7 +311,7 @@ abstract class Route implements IRoute
return null;
}
public function setMethod($method)
public function setMethod($method): IRoute
{
$this->callback = sprintf('%s@%s', $this->getClass(), $method);
@@ -353,11 +353,11 @@ abstract class Route implements IRoute
}
/**
* @return string
* @return string|null
*/
public function getNamespace()
public function getNamespace(): ?string
{
return ($this->namespace === null) ? $this->defaultNamespace : $this->namespace;
return $this->namespace ?? $this->defaultNamespace;
}
/**
@@ -365,7 +365,7 @@ abstract class Route implements IRoute
*
* @return array
*/
public function toArray()
public function toArray(): array
{
$values = [];
@@ -373,15 +373,15 @@ abstract class Route implements IRoute
$values['namespace'] = $this->namespace;
}
if (count($this->requestMethods) !== 0) {
if (\count($this->requestMethods) !== 0) {
$values['method'] = $this->requestMethods;
}
if (count($this->where) !== 0) {
if (\count($this->where) !== 0) {
$values['where'] = $this->where;
}
if (count($this->middlewares) !== 0) {
if (\count($this->middlewares) !== 0) {
$values['middleware'] = $this->middlewares;
}
@@ -434,7 +434,7 @@ abstract class Route implements IRoute
*
* @return array
*/
public function getWhere()
public function getWhere(): array
{
return $this->where;
}
@@ -470,12 +470,12 @@ abstract class Route implements IRoute
*
* @return array
*/
public function getParameters()
public function getParameters(): array
{
/* Sort the parameters after the user-defined param order, if any */
$parameters = [];
if (count($this->originalParameters) !== 0) {
if (\count($this->originalParameters) !== 0) {
$parameters = $this->originalParameters;
}
@@ -494,7 +494,7 @@ abstract class Route implements IRoute
* If this is the first time setting parameters we store them so we
* later can organize the array, in case somebody tried to sort the array.
*/
if (count($parameters) !== 0 && count($this->originalParameters) === 0) {
if (\count($parameters) !== 0 && \count($this->originalParameters) === 0) {
$this->originalParameters = $parameters;
}
@@ -523,7 +523,7 @@ abstract class Route implements IRoute
* @param IMiddleware|string $middleware
* @return static
*/
public function addMiddleware($middleware)
public function addMiddleware($middleware): IRoute
{
$this->middlewares[] = $middleware;
@@ -534,9 +534,9 @@ abstract class Route implements IRoute
* Set middlewares array
*
* @param array $middlewares
* @return $this
* @return static
*/
public function setMiddlewares(array $middlewares)
public function setMiddlewares(array $middlewares): IRoute
{
$this->middlewares = $middlewares;
@@ -546,7 +546,7 @@ abstract class Route implements IRoute
/**
* @return array
*/
public function getMiddlewares()
public function getMiddlewares(): array
{
return $this->middlewares;
}
@@ -570,7 +570,7 @@ abstract class Route implements IRoute
*
* @return string
*/
public function getDefaultParameterRegex()
public function getDefaultParameterRegex(): string
{
return $this->defaultParameterRegex;
}
@@ -24,7 +24,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string $name
* @return bool
*/
public function hasName($name)
public function hasName($name): bool
{
if ($this->name === null) {
return false;
@@ -35,7 +35,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
$method = substr($name, strrpos($name, '.') + 1);
$newName = substr($name, 0, strrpos($name, '.'));
if (in_array($method, $this->names, false) === true && strtolower($this->name) === strtolower($newName)) {
if (\in_array($method, $this->names, true) === true && strtolower($this->name) === strtolower($newName)) {
return true;
}
}
@@ -49,7 +49,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null)
public function findUrl($method = null, $parameters = null, $name = null): string
{
if (strpos($name, '.') !== false) {
$found = array_search(substr($name, strrpos($name, '.') + 1), $this->names, false);
@@ -67,7 +67,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
foreach (static::$requestTypes as $requestType) {
if (stripos($method, $requestType) === 0) {
$method = (string)substr($method, strlen($requestType));
$method = (string)substr($method, \strlen($requestType));
break;
}
}
@@ -77,7 +77,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
$group = $this->getGroup();
if ($group !== null && count($group->getDomains()) !== 0) {
if ($group !== null && \count($group->getDomains()) !== 0) {
$url .= '//' . $group->getDomains()[0];
}
@@ -86,9 +86,9 @@ class RouteController extends LoadableRoute implements IControllerRoute
return '/' . trim($url, '/') . '/';
}
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
@@ -102,12 +102,12 @@ class RouteController extends LoadableRoute implements IControllerRoute
$strippedUrl = trim(str_ireplace($this->url, '/', $url), '/');
$path = explode('/', $strippedUrl);
if (count($path) !== 0) {
if (\count($path) !== 0) {
$method = (isset($path[0]) === false || trim($path[0]) === '') ? $this->defaultMethod : $path[0];
$this->method = $request->getMethod() . ucfirst($method);
$this->parameters = array_slice($path, 1);
$this->parameters = \array_slice($path, 1);
// Set callback
$this->setCallback($this->controller . '@' . $this->method);
@@ -123,7 +123,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
*
* @return string
*/
public function getController()
public function getController(): string
{
return $this->controller;
}
@@ -134,7 +134,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string $controller
* @return static
*/
public function setController($controller)
public function setController($controller): IControllerRoute
{
$this->controller = $controller;
@@ -144,9 +144,9 @@ class RouteController extends LoadableRoute implements IControllerRoute
/**
* Return active method
*
* @return string
* @return string|null
*/
public function getMethod()
public function getMethod(): ?string
{
return $this->method;
}
@@ -157,7 +157,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param string $method
* @return static
*/
public function setMethod($method)
public function setMethod($method): IRoute
{
$this->method = $method;
@@ -171,7 +171,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, $merge = false): IRoute
{
if (isset($values['names']) === true) {
$this->names = $values['names'];
+19 -19
View File
@@ -18,9 +18,9 @@ class RouteGroup extends Route implements IGroupRoute
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request)
public function matchDomain(Request $request): bool
{
if ($this->domains === null || count($this->domains) === 0) {
if ($this->domains === null || \count($this->domains) === 0) {
return true;
}
@@ -28,7 +28,7 @@ class RouteGroup extends Route implements IGroupRoute
$parameters = $this->parseParameters($domain, $request->getHost(), '.*');
if ($parameters !== null && count($parameters) !== 0) {
if ($parameters !== null && \count($parameters) !== 0) {
$this->parameters = $parameters;
@@ -46,9 +46,9 @@ class RouteGroup extends Route implements IGroupRoute
* @param Request $request
* @return bool
*/
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
@@ -64,9 +64,9 @@ class RouteGroup extends Route implements IGroupRoute
* Add exception handler
*
* @param IExceptionHandler|string $handler
* @return static $this
* @return static
*/
public function addExceptionHandler($handler)
public function addExceptionHandler($handler): IGroupRoute
{
$this->exceptionHandlers[] = $handler;
@@ -77,9 +77,9 @@ class RouteGroup extends Route implements IGroupRoute
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
* @return static
*/
public function setExceptionHandlers(array $handlers)
public function setExceptionHandlers(array $handlers): IGroupRoute
{
$this->exceptionHandlers = $handlers;
@@ -91,7 +91,7 @@ class RouteGroup extends Route implements IGroupRoute
*
* @return array
*/
public function getExceptionHandlers()
public function getExceptionHandlers(): array
{
return $this->exceptionHandlers;
}
@@ -101,7 +101,7 @@ class RouteGroup extends Route implements IGroupRoute
*
* @return array
*/
public function getDomains()
public function getDomains(): array
{
return $this->domains;
}
@@ -110,9 +110,9 @@ class RouteGroup extends Route implements IGroupRoute
* Set allowed domains for group.
*
* @param array $domains
* @return $this
* @return static
*/
public function setDomains(array $domains)
public function setDomains(array $domains): IGroupRoute
{
$this->domains = $domains;
@@ -123,7 +123,7 @@ class RouteGroup extends Route implements IGroupRoute
* @param string $prefix
* @return static
*/
public function setPrefix($prefix)
public function setPrefix($prefix): IGroupRoute
{
$this->prefix = '/' . trim($prefix, '/');
@@ -133,9 +133,9 @@ class RouteGroup extends Route implements IGroupRoute
/**
* Set prefix that child-routes will inherit.
*
* @return string
* @return string|null
*/
public function getPrefix()
public function getPrefix(): ?string
{
return $this->prefix;
}
@@ -147,7 +147,7 @@ class RouteGroup extends Route implements IGroupRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, $merge = false): IRoute
{
if (isset($values['prefix']) === true) {
@@ -183,7 +183,7 @@ class RouteGroup extends Route implements IGroupRoute
*
* @return array
*/
public function toArray()
public function toArray(): array
{
$values = [];
@@ -195,7 +195,7 @@ class RouteGroup extends Route implements IGroupRoute
$values['as'] = $this->name;
}
if (count($this->parameters) !== 0) {
if (\count($this->parameters) !== 0) {
$values['parameters'] = $this->parameters;
}
@@ -15,12 +15,12 @@ class RoutePartialGroup extends RouteGroup implements IPartialGroupRoute
* @param Request $request
* @return bool
*/
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
if ($this->prefix !== null) {
/* Parse parameters from current route */
$parameters = $this->parseParameters($this->prefix, $url);
+11 -11
View File
@@ -42,7 +42,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param string $name
* @return bool
*/
public function hasName($name)
public function hasName($name): bool
{
if ($this->name === null) {
return false;
@@ -60,7 +60,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
return (strtolower($this->name) === strtolower($name));
}
public function findUrl($method = null, $parameters = null, $name = null)
public function findUrl($method = null, $parameters = null, $name = null): string
{
$url = array_search($name, $this->names, false);
if ($url !== false) {
@@ -77,9 +77,9 @@ class RouteResource extends LoadableRoute implements IControllerRoute
return true;
}
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}
@@ -114,7 +114,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
}
// Update
if ($id !== null && in_array($method, [static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT], false) === true) {
if ($id !== null && \in_array($method, [static::REQUEST_TYPE_PATCH, static::REQUEST_TYPE_PUT], true) === true) {
return $this->call($this->methodNames['update']);
}
@@ -145,7 +145,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
/**
* @return string
*/
public function getController()
public function getController(): string
{
return $this->controller;
}
@@ -154,14 +154,14 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param string $controller
* @return static
*/
public function setController($controller)
public function setController($controller): IControllerRoute
{
$this->controller = $controller;
return $this;
}
public function setName($name)
public function setName($name): ILoadableRoute
{
$this->name = $name;
@@ -194,9 +194,9 @@ class RouteResource extends LoadableRoute implements IControllerRoute
/**
* Get method names
*
* @return array $this
* @return array
*/
public function getMethodNames()
public function getMethodNames(): array
{
return $this->methodNames;
}
@@ -208,7 +208,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param bool $merge
* @return static
*/
public function setSettings(array $values, $merge = false)
public function setSettings(array $values, $merge = false): IRoute
{
if (isset($values['names']) === true) {
$this->names = $values['names'];
+2 -2
View File
@@ -12,9 +12,9 @@ class RouteUrl extends LoadableRoute
$this->setCallback($callback);
}
public function matchRoute($url, Request $request)
public function matchRoute($url, Request $request): bool
{
if($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false;
}