mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 10:42:14 +00:00
[!!!] Added type definitions to property types
- Request: optimized getIp method and reversed the order so proxy is always checked first.
This commit is contained in:
@@ -27,7 +27,7 @@ class ClassLoader implements IClassLoader
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return object
|
||||
* @return mixed
|
||||
*/
|
||||
public function loadClassMethod($class, string $method, array $parameters)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ interface IClassLoader
|
||||
* @param object $class
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return object
|
||||
* @return mixed
|
||||
*/
|
||||
public function loadClassMethod($class, string $method, array $parameters);
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@ class EventArgument implements IEventArgument
|
||||
* Event name
|
||||
* @var string
|
||||
*/
|
||||
protected $eventName;
|
||||
protected string $eventName;
|
||||
|
||||
/**
|
||||
* @var Router
|
||||
*/
|
||||
protected $router;
|
||||
protected Router $router;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
protected array $arguments = [];
|
||||
|
||||
public function __construct(string $eventName, Router $router, array $arguments = [])
|
||||
{
|
||||
|
||||
@@ -9,12 +9,12 @@ class ClassNotFoundHttpException extends NotFoundHttpException
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
protected string $class;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $method;
|
||||
protected ?string $method = null;
|
||||
|
||||
public function __construct(string $class, ?string $method = null, string $message = "", int $code = 0, Throwable $previous = null)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ class CallbackExceptionHandler implements IExceptionHandler
|
||||
/**
|
||||
* @var Closure
|
||||
*/
|
||||
protected $callback;
|
||||
protected Closure $callback;
|
||||
|
||||
public function __construct(Closure $callback)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ class DebugEventHandler implements IEventHandler
|
||||
* Debug callback
|
||||
* @var Closure
|
||||
*/
|
||||
protected $callback;
|
||||
protected Closure $callback;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ class EventHandler implements IEventHandler
|
||||
* All available events
|
||||
* @var array
|
||||
*/
|
||||
public static $events = [
|
||||
public static array $events = [
|
||||
self::EVENT_ALL,
|
||||
self::EVENT_INIT,
|
||||
self::EVENT_LOAD,
|
||||
@@ -120,7 +120,7 @@ class EventHandler implements IEventHandler
|
||||
* List of all registered events
|
||||
* @var array
|
||||
*/
|
||||
private $registeredEvents = [];
|
||||
private array $registeredEvents = [];
|
||||
|
||||
/**
|
||||
* Register new event
|
||||
|
||||
@@ -12,17 +12,17 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
protected string $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
protected ?string $name = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $regex;
|
||||
protected ?string $regex = null;
|
||||
|
||||
/**
|
||||
* Loads and renders middlewares-classes
|
||||
@@ -195,7 +195,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
|
||||
*/
|
||||
public function hasName(string $name): bool
|
||||
{
|
||||
return strtolower((string)$this->name) === strtolower((string)$name);
|
||||
return strtolower((string)$this->name) === strtolower($name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,37 +18,37 @@ abstract class Route implements IRoute
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $filterEmptyParams = true;
|
||||
protected bool $filterEmptyParams = true;
|
||||
|
||||
/**
|
||||
* If true the last parameter of the route will include ending trail/slash.
|
||||
* @var bool
|
||||
*/
|
||||
protected $slashParameterEnabled = false;
|
||||
protected bool $slashParameterEnabled = false;
|
||||
|
||||
/**
|
||||
* Default regular expression used for parsing parameters.
|
||||
* @var string|null
|
||||
*/
|
||||
protected $defaultParameterRegex;
|
||||
protected $paramModifiers = '{}';
|
||||
protected $paramOptionalSymbol = '?';
|
||||
protected $urlRegex = '/^%s\/?$/u';
|
||||
protected $group;
|
||||
protected $parent;
|
||||
protected ?string $defaultParameterRegex = null;
|
||||
protected string $paramModifiers = '{}';
|
||||
protected string $paramOptionalSymbol = '?';
|
||||
protected string $urlRegex = '/^%s\/?$/u';
|
||||
protected ?IGroupRoute $group = null;
|
||||
protected ?IRoute $parent = null;
|
||||
/**
|
||||
* @var string|callable|null
|
||||
*/
|
||||
protected $callback;
|
||||
protected $defaultNamespace;
|
||||
protected ?string $defaultNamespace = null;
|
||||
|
||||
/* Default options */
|
||||
protected $namespace;
|
||||
protected $requestMethods = [];
|
||||
protected $where = [];
|
||||
protected $parameters = [];
|
||||
protected $originalParameters = [];
|
||||
protected $middlewares = [];
|
||||
protected ?string $namespace = null;
|
||||
protected array $requestMethods = [];
|
||||
protected array $where = [];
|
||||
protected array $parameters = [];
|
||||
protected array $originalParameters = [];
|
||||
protected array $middlewares = [];
|
||||
|
||||
/**
|
||||
* Render route
|
||||
|
||||
@@ -6,10 +6,10 @@ use Pecee\Http\Request;
|
||||
|
||||
class RouteController extends LoadableRoute implements IControllerRoute
|
||||
{
|
||||
protected $defaultMethod = 'index';
|
||||
protected $controller;
|
||||
protected $method;
|
||||
protected $names = [];
|
||||
protected string $defaultMethod = 'index';
|
||||
protected string $controller;
|
||||
protected ?string $method = null;
|
||||
protected array $names = [];
|
||||
|
||||
public function __construct($url, $controller)
|
||||
{
|
||||
|
||||
@@ -7,12 +7,12 @@ use Pecee\SimpleRouter\Handlers\IExceptionHandler;
|
||||
|
||||
class RouteGroup extends Route implements IGroupRoute
|
||||
{
|
||||
protected $urlRegex = '/^%s\/?/u';
|
||||
protected $prefix;
|
||||
protected $name;
|
||||
protected $domains = [];
|
||||
protected $exceptionHandlers = [];
|
||||
protected $mergeExceptionHandlers = true;
|
||||
protected string $urlRegex = '/^%s\/?/u';
|
||||
protected ?string $prefix = null;
|
||||
protected ?string $name = null;
|
||||
protected array $domains = [];
|
||||
protected array $exceptionHandlers = [];
|
||||
protected bool $mergeExceptionHandlers = true;
|
||||
|
||||
/**
|
||||
* Method called to check if a domain matches
|
||||
@@ -22,7 +22,7 @@ class RouteGroup extends Route implements IGroupRoute
|
||||
*/
|
||||
public function matchDomain(Request $request): bool
|
||||
{
|
||||
if ($this->domains === null || count($this->domains) === 0) {
|
||||
if (count($this->domains) === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use Pecee\Http\Request;
|
||||
|
||||
class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
{
|
||||
protected $urls = [
|
||||
protected array $urls = [
|
||||
'index' => '',
|
||||
'create' => 'create',
|
||||
'store' => '',
|
||||
@@ -16,7 +16,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
'destroy' => '',
|
||||
];
|
||||
|
||||
protected $methodNames = [
|
||||
protected array $methodNames = [
|
||||
'index' => 'index',
|
||||
'create' => 'create',
|
||||
'store' => 'store',
|
||||
@@ -26,8 +26,8 @@ class RouteResource extends LoadableRoute implements IControllerRoute
|
||||
'destroy' => 'destroy',
|
||||
];
|
||||
|
||||
protected $names = [];
|
||||
protected $controller;
|
||||
protected array $names = [];
|
||||
protected string $controller;
|
||||
|
||||
public function __construct($url, $controller)
|
||||
{
|
||||
|
||||
@@ -28,56 +28,56 @@ class Router
|
||||
* Current request
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
protected Request $request;
|
||||
|
||||
/**
|
||||
* Defines if a route is currently being processed.
|
||||
* @var bool
|
||||
*/
|
||||
protected $isProcessingRoute;
|
||||
protected bool $isProcessingRoute;
|
||||
|
||||
/**
|
||||
* Defines all data from current processing route.
|
||||
* @var ILoadableRoute
|
||||
*/
|
||||
protected $currentProcessingRoute;
|
||||
protected ILoadableRoute $currentProcessingRoute;
|
||||
|
||||
/**
|
||||
* All added routes
|
||||
* @var array
|
||||
*/
|
||||
protected $routes = [];
|
||||
protected array $routes = [];
|
||||
|
||||
/**
|
||||
* List of processed routes
|
||||
* @var array|ILoadableRoute[]
|
||||
*/
|
||||
protected $processedRoutes = [];
|
||||
protected array $processedRoutes = [];
|
||||
|
||||
/**
|
||||
* Stack of routes used to keep track of sub-routes added
|
||||
* when a route is being processed.
|
||||
* @var array
|
||||
*/
|
||||
protected $routeStack = [];
|
||||
protected array$routeStack = [];
|
||||
|
||||
/**
|
||||
* List of added bootmanagers
|
||||
* @var array
|
||||
*/
|
||||
protected $bootManagers = [];
|
||||
protected array $bootManagers = [];
|
||||
|
||||
/**
|
||||
* Csrf verifier class
|
||||
* @var BaseCsrfVerifier|null
|
||||
*/
|
||||
protected $csrfVerifier;
|
||||
protected ?BaseCsrfVerifier $csrfVerifier;
|
||||
|
||||
/**
|
||||
* Get exception handlers
|
||||
* @var array
|
||||
*/
|
||||
protected $exceptionHandlers = [];
|
||||
protected array $exceptionHandlers = [];
|
||||
|
||||
/**
|
||||
* List of loaded exception that has been loaded.
|
||||
@@ -85,44 +85,44 @@ class Router
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $loadedExceptionHandlers = [];
|
||||
protected array $loadedExceptionHandlers = [];
|
||||
|
||||
/**
|
||||
* Enable or disabled debugging
|
||||
* @var bool
|
||||
*/
|
||||
protected $debugEnabled = false;
|
||||
protected bool $debugEnabled = false;
|
||||
|
||||
/**
|
||||
* The start time used when debugging is enabled
|
||||
* @var float
|
||||
*/
|
||||
protected $debugStartTime;
|
||||
protected float $debugStartTime;
|
||||
|
||||
/**
|
||||
* List containing all debug messages
|
||||
* @var array
|
||||
*/
|
||||
protected $debugList = [];
|
||||
protected array $debugList = [];
|
||||
|
||||
/**
|
||||
* Contains any registered event-handler.
|
||||
* @var array
|
||||
*/
|
||||
protected $eventHandlers = [];
|
||||
protected array $eventHandlers = [];
|
||||
|
||||
/**
|
||||
* Class loader instance
|
||||
* @var IClassLoader
|
||||
*/
|
||||
protected $classLoader;
|
||||
protected IClassLoader $classLoader;
|
||||
|
||||
/**
|
||||
* When enabled the router will render all routes that matches.
|
||||
* When disabled the router will stop execution when first route is found.
|
||||
* @var bool
|
||||
*/
|
||||
protected $renderMultipleRoutes = false;
|
||||
protected bool $renderMultipleRoutes = false;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
@@ -345,7 +345,7 @@ class Router
|
||||
try {
|
||||
/* Verify csrf token for request */
|
||||
$this->csrfVerifier->handle($this->request);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,19 +37,19 @@ class SimpleRouter
|
||||
* Default namespace added to all routes
|
||||
* @var string|null
|
||||
*/
|
||||
protected static $defaultNamespace;
|
||||
protected static ?string $defaultNamespace = null;
|
||||
|
||||
/**
|
||||
* The response object
|
||||
* @var Response
|
||||
*/
|
||||
protected static $response;
|
||||
protected static Response $response;
|
||||
|
||||
/**
|
||||
* Router instance
|
||||
* @var Router
|
||||
*/
|
||||
protected static $router;
|
||||
protected static ?Router $router = null;
|
||||
|
||||
/**
|
||||
* Start routing
|
||||
@@ -493,7 +493,7 @@ class SimpleRouter
|
||||
* Prepends the default namespace to all new routes added.
|
||||
*
|
||||
* @param ILoadableRoute|IRoute $route
|
||||
* @return IRoute
|
||||
* @return IRoute|ILoadableRoute
|
||||
*/
|
||||
public static function addDefaultNamespace(IRoute $route): IRoute
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user