Skip to content

Commit

Permalink
allow with parameter to take any type of data
Browse files Browse the repository at this point in the history
  • Loading branch information
IngeniozIT committed Apr 20, 2024
1 parent 312a2d6 commit 287855a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 30 deletions.
106 changes: 78 additions & 28 deletions src/Route.php
Expand Up @@ -39,84 +39,134 @@

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function get(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function get(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::GET, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function post(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function post(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::POST, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function put(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function put(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::PUT, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function patch(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function patch(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::PATCH, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function delete(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function delete(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::DELETE, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function head(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function head(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::HEAD, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function options(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function options(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::OPTIONS, $path, $callback, $where, $with, $name);
}

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function any(string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
public static function any(
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
return new RouteElement(self::ANY, $path, $callback, $where, $with, $name);
}

/**
* @param string[] $methods
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public static function some(array $methods, string $path, mixed $callback, array $where = [], array $with = [], ?string $name = null): RouteElement
{
$method = array_reduce($methods, static fn($carry, $methodString): int => $carry | self::METHODS[strtoupper($methodString)], 0);
public static function some(
array $methods,
string $path,
mixed $callback,
array $where = [],
array $with = [],
?string $name = null
): RouteElement {
$method = array_reduce(
$methods,
static fn($carry, $methodString): int => $carry | self::METHODS[strtoupper($methodString)],
0
);

return new RouteElement($method, $path, $callback, $where, $with, $name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Route/RouteElement.php
Expand Up @@ -37,7 +37,7 @@

/**
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public function __construct(
public int $method,
Expand Down
2 changes: 1 addition & 1 deletion src/RouteGroup.php
Expand Up @@ -18,7 +18,7 @@ final class RouteGroup
* @param mixed[] $middlewares
* @param mixed[] $conditions
* @param array<string, string> $where
* @param array<string, string> $with
* @param array<string, mixed> $with
*/
public function __construct(
array $routes,
Expand Down

0 comments on commit 287855a

Please sign in to comment.