Skip to content

Commit

Permalink
Route arguments support
Browse files Browse the repository at this point in the history
  • Loading branch information
websharik committed Aug 11, 2022
1 parent d712e49 commit 10b73a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 6 additions & 3 deletions AltoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ public function addMatchTypes(array $matchTypes)
* @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE)
* @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id]
* @param mixed $target The target where this route should point to. Can be anything.
* @param mixed $arguments Optional arguments to target function.
* @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
* @throws Exception
*/
public function map($method, $route, $target, $name = null)
public function map($method, $route, $target, $arguments, $name = null)
{

$this->routes[] = [$method, $route, $target, $name];
$this->routes[] = [$method, $route, $target, $arguments, $name];

if ($name) {
if (isset($this->namedRoutes[$name])) {
Expand Down Expand Up @@ -214,7 +215,7 @@ public function match($requestUrl = null, $requestMethod = null, $once = true)

$matches = [];
foreach ($this->routes as $handler) {
list($methods, $route, $target, $name) = $handler;
list($methods, $route, $target, $arguments, $name) = $handler;

$method_match = (stripos($methods, $requestMethod) !== false);

Expand Down Expand Up @@ -258,12 +259,14 @@ public function match($requestUrl = null, $requestMethod = null, $once = true)
return [
'target' => $target,
'params' => $params,
'arguments' => $arguments,
'name' => $name
];
} else {
$matches[] = [
'target' => $target,
'params' => $params,
'arguments' => $arguments,
'name' => $name
];
}
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# AltoRouter ![PHP status](https://github.com/dannyvankooten/AltoRouter/workflows/PHP/badge.svg) [![Latest Stable Version](https://poser.pugx.org/altorouter/altorouter/v/stable.svg)](https://packagist.org/packages/altorouter/altorouter) [![License](https://poser.pugx.org/altorouter/altorouter/license.svg)](https://packagist.org/packages/altorouter/altorouter)

# AltoRouter [![Build Status](https://img.shields.io/travis/dannyvankooten/AltoRouter/master)](https://travis-ci.org/dannyvankooten/AltoRouter) [![Latest Stable Version](https://poser.pugx.org/altorouter/altorouter/v/stable.svg)](https://packagist.org/packages/altorouter/altorouter) [![License](https://poser.pugx.org/altorouter/altorouter/license.svg)](https://packagist.org/packages/altorouter/altorouter) [![Code Climate](https://codeclimate.com/github/dannyvankooten/AltoRouter/badges/gpa.svg)](https://codeclimate.com/github/dannyvankooten/AltoRouter) [![Test Coverage](https://codeclimate.com/github/dannyvankooten/AltoRouter/badges/coverage.svg)](https://codeclimate.com/github/dannyvankooten/AltoRouter)
AltoRouter is a small but powerful routing class, heavily inspired by [klein.php](https://github.com/chriso/klein.php/).

```php
Expand Down

0 comments on commit 10b73a9

Please sign in to comment.