Skip to content

Commit a962376

Browse files
committed
Route: getTargetPresenter() generalized to interface IFixedTargetPresenters
1 parent c2d1f55 commit a962376

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (http://nette.org)
5+
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6+
*/
7+
8+
namespace Nette\Application;
9+
10+
use Nette;
11+
12+
13+
/**
14+
* Router with fixed target presenters.
15+
*
16+
* @author Jan Tvrdik
17+
*/
18+
interface IFixedTargetPresenters extends IRouter
19+
{
20+
21+
/**
22+
* Returns list of possible target presenters or NULL if the list is dynamic.
23+
* @return string[]|NULL
24+
*/
25+
function getTargetPresenters();
26+
27+
}

src/Application/Routers/Route.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @property-read int $flags
2424
* @property-read string|FALSE $targetPresenter
2525
*/
26-
class Route extends Nette\Object implements Application\IRouter
26+
class Route extends Nette\Object implements Application\IRouter, Application\IFixedTargetPresenters
2727
{
2828
const PRESENTER_KEY = 'presenter';
2929
const MODULE_KEY = 'module';
@@ -661,13 +661,12 @@ public function getFlags()
661661

662662
/**
663663
* Proprietary cache aim.
664-
* @internal
665-
* @return string|FALSE
664+
* @return string[]|NULL
666665
*/
667-
public function getTargetPresenter()
666+
public function getTargetPresenters()
668667
{
669668
if ($this->flags & self::ONE_WAY) {
670-
return FALSE;
669+
return array();
671670
}
672671

673672
$m = $this->metadata;
@@ -682,7 +681,7 @@ public function getTargetPresenter()
682681
}
683682

684683
if (isset($m[self::PRESENTER_KEY]['fixity']) && $m[self::PRESENTER_KEY]['fixity'] === self::CONSTANT) {
685-
return $module . $m[self::PRESENTER_KEY][self::VALUE];
684+
return array($module . $m[self::PRESENTER_KEY][self::VALUE]);
686685
}
687686
return NULL;
688687
}

src/Application/Routers/RouteList.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Nette\Application\Routers;
99

1010
use Nette;
11+
use Nette\Application\IFixedTargetPresenters;
1112

1213

1314
/**
@@ -62,18 +63,15 @@ public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\U
6263
$routes['*'] = array();
6364

6465
foreach ($this as $route) {
65-
$presenter = $route instanceof Route ? $route->getTargetPresenter() : NULL;
66-
67-
if ($presenter === FALSE) {
68-
continue;
69-
}
70-
71-
if (is_string($presenter)) {
72-
$presenter = strtolower($presenter);
73-
if (!isset($routes[$presenter])) {
74-
$routes[$presenter] = $routes['*'];
66+
$presenters = $route instanceof IFixedTargetPresenters ? $route->getTargetPresenters() : NULL;
67+
if (is_array($presenters)) {
68+
foreach ($presenters as $presenter) {
69+
$presenter = strtolower($presenter);
70+
if (!isset($routes[$presenter])) {
71+
$routes[$presenter] = $routes['*'];
72+
}
73+
$routes[$presenter][] = $route;
7574
}
76-
$routes[$presenter][] = $route;
7775

7876
} else {
7977
foreach ($routes as $id => $foo) {

0 commit comments

Comments
 (0)