Skip to content

Commit

Permalink
Route: action is mandatory when defined as 'Presenter:'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 3, 2015
1 parent 061a054 commit a4d3a1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ class Route extends Nette\Object implements Application\IRouter
public function __construct($mask, $metadata = array(), $flags = 0)
{
if (is_string($metadata)) {
$a = strrpos($metadata, ':');
$a = strrpos($tmp = $metadata, ':');
if (!$a) {
throw new Nette\InvalidArgumentException("Second argument must be array or string in format Presenter:action, '$metadata' given.");
}
$metadata = array(
self::PRESENTER_KEY => substr($metadata, 0, $a),
'action' => $a === strlen($metadata) - 1 ? NULL : substr($metadata, $a + 1),
);
$metadata = array(self::PRESENTER_KEY => substr($tmp, 0, $a));
if ($a < strlen($tmp) - 1) {
$metadata['action'] = substr($tmp, $a + 1);
}
} elseif ($metadata instanceof \Closure || $metadata instanceof Nette\Callback) {
$metadata = array(
self::PRESENTER_KEY => 'Nette:Micro',
Expand Down
10 changes: 10 additions & 0 deletions tests/Routers/Route.mandatoryAction.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ testRouteIn($route, '/default', 'Default', array(
'action' => 'default',
'test' => 'testvalue',
), '/default?test=testvalue');

testRouteIn($route, '/', NULL);


$route = new Route('<action>', 'Front:Default:');

testRouteIn($route, '/default', 'Front:Default', array(
'action' => 'default',
'test' => 'testvalue',
), '/default?test=testvalue');

0 comments on commit a4d3a1a

Please sign in to comment.