Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Phroute/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public function dispatch($httpMethod, $uri)
}

$resolvedHandler = $this->handlerResolver->resolve($handler);

$response = call_user_func_array($resolvedHandler, $vars);

if ($this->handlerResolver instanceof NamedParameterHandlerResolverInterface) {
$response = call_user_func($resolvedHandler, $vars);
} else {
$response = call_user_func_array($resolvedHandler, $vars);
}

return $this->dispatchFilters($afterFilter, $response);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Phroute/NamedParameterHandlerResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Phroute\Phroute;

interface NamedParameterHandlerResolverInterface extends HandlerResolverInterface
{
}
47 changes: 47 additions & 0 deletions test/Dispatcher/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,53 @@ public function testRestfulMethods()

$this->assertEquals($methods, array_keys($data->getStaticRoutes()['user']));
}

public function testParameterHandler()
{
$handler = $this
->getMockBuilder('\Phroute\Phroute\HandlerResolverInterface')
->getMock();

$handler
->method('resolve')
->willReturnCallback(function () {
$handler = function($name, $country) {
return [$name, $country];
};

return $handler;
});

$r = $this->router();
$r->get('/{name}/{country}', function (){});

$response = (new Dispatcher($r->getData(), $handler))->dispatch('GET', '/joe/uk');
$this->assertSame(['joe', 'uk'], $response);
}

public function testNamedParameterHandler()
{
$handler = $this
->getMockBuilder('\Phroute\Phroute\NamedParameterHandlerResolverInterface')
->getMock();

$handler
->method('resolve')
->willReturnCallback(function () {
$handler = function($args) {
return $args;
};

return $handler;
});

$r = $this->router();
$r->get('/{name}/{country}', function (){});

$response = (new Dispatcher($r->getData(), $handler))->dispatch('GET', '/joe/uk');

$this->assertSame(['name' => 'joe', 'country' => 'uk'], $response);
}

public function provideFoundDispatchCases()
{
Expand Down