Skip to content

Commit 64119b2

Browse files
author
Skylear
committed
📑 write docblocks for the router methods
1 parent 8a523c3 commit 64119b2

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/Splashsky/Router.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,53 @@ public static function add(string $route, callable|string $action, string|array
2929
return new self;
3030
}
3131

32+
/**
33+
* Shorthand function to define a GET route
34+
*
35+
* @param string $route
36+
* @param callable $action
37+
*/
3238
public static function get(string $route, callable $action)
3339
{
3440
return self::add($route, $action, 'GET');
3541
}
3642

43+
/**
44+
* Default function to define a POST route
45+
*
46+
* @param string $route
47+
* @param callable $action
48+
*/
3749
public static function post(string $route, callable $action)
3850
{
3951
return self::add($route, $action, 'POST');
4052
}
4153

54+
/**
55+
* Return all routes currently registered
56+
*
57+
* @return array
58+
*/
4259
public static function getAllRoutes()
4360
{
4461
return self::$routes;
4562
}
4663

64+
/**
65+
* Defines an action to be called when a path isn't found - i.e. a 404
66+
*
67+
* @param callable $action
68+
*/
4769
public static function pathNotFound(callable $action)
4870
{
4971
self::$pathNotFound = $action;
5072
}
5173

74+
/**
75+
* Defines an action to be called with a method isn't allowed on a route - i.e. a 405
76+
*
77+
* @param callable $action
78+
*/
5279
public static function methodNotAllowed(callable $action)
5380
{
5481
self::$methodNotAllowed = $action;
@@ -65,6 +92,16 @@ public static function setDefaultConstraint(string $constraint = '([\w\-]+)')
6592
self::$defaultConstraint = $constraint;
6693
}
6794

95+
/**
96+
* Define a constraint for a route parameter. If only passing one parameter,
97+
* provide the parameter name as first argument and constraint as second. If
98+
* adding constraints for multiple parameters, pass an array of 'parameter' => 'constraint'
99+
* pairs.
100+
*
101+
* @param string|array $parameter
102+
* @param string $constraint
103+
* @return Router
104+
*/
68105
public static function with(string|array $parameter, string $constraint = '')
69106
{
70107
if (is_array($parameter)) {
@@ -80,6 +117,12 @@ public static function with(string|array $parameter, string $constraint = '')
80117
return new self;
81118
}
82119

120+
/**
121+
* Tokenizes the given URI using our constraint rules and returns the tokenized URI
122+
*
123+
* @param string $uri
124+
* @return string
125+
*/
83126
private static function tokenize(string $uri)
84127
{
85128
$constraints = array_keys(self::$constraints);
@@ -100,6 +143,13 @@ private static function tokenize(string $uri)
100143
return $uri;
101144
}
102145

146+
/**
147+
* Runs the router. Accepts a base path from which to serve the routes, and optionally whether you want to try
148+
* and match multiple routes.
149+
*
150+
* @param string $basePath
151+
* @param boolean $multimatch
152+
*/
103153
public static function run(string $basePath = '', bool $multimatch = false)
104154
{
105155
$basePath = rtrim($basePath, '/');

0 commit comments

Comments
 (0)