Skip to content

Commit 4e70651

Browse files
authored
Merge pull request #6 from barryvdh/patch-1
Return Route instance from methods
2 parents 9217b49 + 232336f commit 4e70651

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Routing/Router.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ public function __construct(Container $container = null)
2727
$this->routes = new RouteCollection;
2828
}
2929

30-
public function from(string $pattern, $action)
30+
public function from(string $pattern, $action) : Route
3131
{
32-
$this->addRoute(Route::FROM, $pattern, $action);
32+
return $this->addRoute(Route::FROM, $pattern, $action);
3333
}
3434

35-
public function to(string $pattern, $action)
35+
public function to(string $pattern, $action) : Route
3636
{
37-
$this->addRoute(Route::TO, $pattern, $action);
37+
return $this->addRoute(Route::TO, $pattern, $action);
3838
}
3939

40-
public function cc(string $pattern, $action)
40+
public function cc(string $pattern, $action) : Route
4141
{
42-
$this->addRoute(Route::CC, $pattern, $action);
42+
return $this->addRoute(Route::CC, $pattern, $action);
4343
}
4444

45-
public function subject(string $pattern, $action)
45+
public function subject(string $pattern, $action) : Route
4646
{
47-
$this->addRoute(Route::SUBJECT, $pattern, $action);
47+
return $this->addRoute(Route::SUBJECT, $pattern, $action);
4848
}
4949

5050
public function fallback($action)
@@ -57,12 +57,16 @@ public function catchAll($action)
5757
$this->catchAllRoute = $this->createRoute(Route::CATCH_ALL, '', $action);
5858
}
5959

60-
protected function addRoute(string $subject, string $pattern, $action)
60+
protected function addRoute(string $subject, string $pattern, $action) : Route
6161
{
62-
$this->routes->add($this->createRoute($subject, $pattern, $action));
62+
$route = $this->createRoute($subject, $pattern, $action);
63+
64+
$this->routes->add($route);
65+
66+
return $route;
6367
}
6468

65-
protected function createRoute(string $subject, string $pattern, $action)
69+
protected function createRoute(string $subject, string $pattern, $action) : Route
6670
{
6771
return (new Route($subject, $pattern, $action))
6872
->setContainer($this->container);

0 commit comments

Comments
 (0)