Skip to content

Commit

Permalink
Fix output of getActionName()
Browse files Browse the repository at this point in the history
  • Loading branch information
joelambert committed Jul 13, 2018
1 parent c0b78cb commit 4cf9696
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

v3.2.1
- Fix `getActionName()` output

v3.2.0
- Add `getRoutes()` method to Router
- Add `getActionName()` method to Route
Expand Down
10 changes: 7 additions & 3 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,18 @@ public function getActionName()
{
$callableName = null;

if (isset($this->controllerName)) {
return $this->controllerName;
if (isset($this->controllerName) && isset($this->controllerMethod)) {
return $this->controllerName . '@' . $this->controllerMethod;
}

if (is_callable($this->action, false, $callableName)) {
list($controller, $method) = explode('::', $callableName);

return $controller;
if ($controller === 'Closure') {
return $controller;
}

return $controller . '@' . $method;
}
}
}
6 changes: 3 additions & 3 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function can_get_route_action_name_when_callable()
$router = new Router;
$route = $router->get('test/123', [TestCallableController::class, 'testStatic']);

$this->assertSame(TestCallableController::class, $route->getActionName());
$this->assertSame(TestCallableController::class.'@testStatic', $route->getActionName());
}

/** @test */
Expand All @@ -89,7 +89,7 @@ public function can_get_route_action_name_when_callable_instance()
$controller = new TestCallableController;
$route = $router->get('test/123', [$controller, 'test']);

$this->assertSame(TestCallableController::class, $route->getActionName());
$this->assertSame(TestCallableController::class.'@test', $route->getActionName());
}

/** @test */
Expand All @@ -98,7 +98,7 @@ public function can_get_route_action_name_when_controller_string()
$router = new Router;
$route = $router->get('test/123', TestCallableController::class.'@test');

$this->assertSame(TestCallableController::class, $route->getActionName());
$this->assertSame(TestCallableController::class.'@test', $route->getActionName());
}
}

Expand Down

0 comments on commit 4cf9696

Please sign in to comment.