Merge pull request #636 from flightphp/docs/allow-arrays-route-controllers-and-middlewares

docs: add array{0: class-string, 1: method} to support phpstan level …
event-tweaks
n0nag0n 3 weeks ago committed by GitHub
commit a0a2b7cb79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -63,7 +63,7 @@
"test-server": "echo \"Running Test Server\" && php -S localhost:8000 -t tests/server/",
"test-server-v2": "echo \"Running Test Server\" && php -S localhost:8000 -t tests/server-v2/",
"test-coverage:win": "del clover.xml && phpunit --coverage-html=coverage --coverage-clover=clover.xml && coverage-check clover.xml 100",
"lint": "phpstan --no-progress -cphpstan.neon",
"lint": "phpstan --no-progress --memory-limit=256M -cphpstan.neon",
"beautify": "phpcbf --standard=phpcs.xml",
"phpcs": "phpcs --standard=phpcs.xml -n",
"post-install-cmd": [

@ -34,19 +34,19 @@ use flight\net\Route;
* @method EventDispatcher eventDispatcher() Gets event dispatcher
*
* # Routing
* @method Route route(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method Route route(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a URL to a callback function with all applicable methods
* @method void group(string $pattern, callable $callback, array<int, callable|object> $group_middlewares = [])
* @method void group(string $pattern, callable $callback, (class-string|callable|array{0: class-string, 1: string})[] $group_middlewares = [])
* Groups a set of routes together under a common prefix.
* @method Route post(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method Route post(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a POST URL to a callback function.
* @method Route put(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method Route put(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a PUT URL to a callback function.
* @method Route patch(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method Route patch(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a PATCH URL to a callback function.
* @method Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method Route delete(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a DELETE URL to a callback function.
* @method void resource(string $pattern, string $controllerClass, array<string, string|array<string>> $methods = [])
* @method void resource(string $pattern, class-string $controllerClass, array<string, string|array<string>> $methods = [])
* Adds standardized RESTful routes for a controller.
* @method Router router() Gets router
* @method string getUrl(string $alias) Gets a url from an alias
@ -85,10 +85,29 @@ class Engine
* @var array<string> List of methods that can be extended in the Engine class.
*/
private const MAPPABLE_METHODS = [
'start', 'stop', 'route', 'halt', 'error', 'notFound',
'render', 'redirect', 'etag', 'lastModified', 'json', 'jsonHalt', 'jsonp',
'post', 'put', 'patch', 'delete', 'group', 'getUrl', 'download', 'resource',
'onEvent', 'triggerEvent'
'start',
'stop',
'route',
'halt',
'error',
'notFound',
'render',
'redirect',
'etag',
'lastModified',
'json',
'jsonHalt',
'jsonp',
'post',
'put',
'patch',
'delete',
'group',
'getUrl',
'download',
'resource',
'onEvent',
'triggerEvent'
];
/** @var array<string, mixed> Stored variables. */

@ -34,19 +34,19 @@ require_once __DIR__ . '/autoload.php';
* @method EventDispatcher eventDispatcher() Gets event dispatcher
*
* # Routing
* @method static Route route(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method static Route route(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Maps a URL pattern to a callback with all applicable methods.
* @method static void group(string $pattern, callable $callback, callable[] $group_middlewares = [])
* @method static void group(string $pattern, callable $callback, (class-string|callable|array{0: class-string, 1: string})[] $group_middlewares = [])
* Groups a set of routes together under a common prefix.
* @method static Route post(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method static Route post(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a POST URL to a callback function.
* @method static Route put(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method static Route put(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a PUT URL to a callback function.
* @method static Route patch(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method static Route patch(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a PATCH URL to a callback function.
* @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* @method static Route delete(string $pattern, callable|string|array{0: class-string, 1: string} $callback, bool $pass_route = false, string $alias = '')
* Routes a DELETE URL to a callback function.
* @method static void resource(string $pattern, string $controllerClass, array<string, string|array<string>> $methods = [])
* @method static void resource(string $pattern, class-string $controllerClass, array<string, string|array<string>> $methods = [])
* Adds standardized RESTful routes for a controller.
* @method static Router router() Returns Router instance.
* @method static string getUrl(string $alias, array<string, mixed> $params = []) Gets a url from an alias

@ -56,7 +56,15 @@ class Router
*
* @var array<int, string>
*/
protected array $allowedMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
protected array $allowedMethods = [
'GET',
'POST',
'PUT',
'PATCH',
'DELETE',
'HEAD',
'OPTIONS'
];
/**
* Gets mapped routes.
@ -80,7 +88,7 @@ class Router
* Maps a URL pattern to a callback function.
*
* @param string $pattern URL pattern to match.
* @param callable|string $callback Callback function or string class->method
* @param callable|string|array{0: class-string, 1: string} $callback Callback function or string `class->method`
* @param bool $pass_route Pass the matching route object to the callback.
* @param string $route_alias Alias for the route.
*/
@ -133,7 +141,7 @@ class Router
* Creates a GET based route
*
* @param string $pattern URL pattern to match
* @param callable|string $callback Callback function or string class->method
* @param callable|string|array{0: class-string, 1: string} $callback Callback function or string `class->method`
* @param bool $pass_route Pass the matching route object to the callback
* @param string $alias Alias for the route
*/
@ -146,7 +154,7 @@ class Router
* Creates a POST based route
*
* @param string $pattern URL pattern to match
* @param callable|string $callback Callback function or string class->method
* @param callable|string|array{0: class-string, 1: string} $callback Callback function or string `class->method`
* @param bool $pass_route Pass the matching route object to the callback
* @param string $alias Alias for the route
*/
@ -159,7 +167,7 @@ class Router
* Creates a PUT based route
*
* @param string $pattern URL pattern to match
* @param callable|string $callback Callback function or string class->method
* @param callable|string|array{0: class-string, 1: string} $callback Callback function or string `class->method`
* @param bool $pass_route Pass the matching route object to the callback
* @param string $alias Alias for the route
*/
@ -172,7 +180,7 @@ class Router
* Creates a PATCH based route
*
* @param string $pattern URL pattern to match
* @param callable|string $callback Callback function or string class->method
* @param callable|string|array{0: class-string, 1: string} $callback Callback function or string `class->method`
* @param bool $pass_route Pass the matching route object to the callback
* @param string $alias Alias for the route
*/
@ -185,7 +193,7 @@ class Router
* Creates a DELETE based route
*
* @param string $pattern URL pattern to match
* @param callable|string $callback Callback function or string class->method
* @param callable|string|array{0: class-string, 1: string} $callback Callback function or string `class->method`
* @param bool $pass_route Pass the matching route object to the callback
* @param string $alias Alias for the route
*/
@ -199,7 +207,7 @@ class Router
*
* @param string $groupPrefix group URL prefix (such as /api/v1)
* @param callable $callback The necessary calling that holds the Router class
* @param array<int, callable|object> $groupMiddlewares
* @param (class-string|callable|array{0: class-string, 1: string})[] $groupMiddlewares
* The middlewares to be applied to the group. Example: `[$middleware1, $middleware2]`
*/
public function group(string $groupPrefix, callable $callback, array $groupMiddlewares = []): void

Loading…
Cancel
Save