Skip to content

Commit

Permalink
Route: changed internal getTargetPresenter() to getTargetPresenters()…
Browse files Browse the repository at this point in the history
… that returns array (inspired by #40)
  • Loading branch information
dg committed Jan 26, 2015
1 parent d8c7ad8 commit 032d6b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
13 changes: 6 additions & 7 deletions src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @property-read string $mask
* @property-read array $defaults
* @property-read int $flags
* @property-read string|FALSE $targetPresenter
*/
class Route extends Nette\Object implements Application\IRouter
{
Expand Down Expand Up @@ -674,12 +673,12 @@ public function getFlags()
/**
* Proprietary cache aim.
* @internal
* @return string|FALSE
* @return string[]|NULL
*/
public function getTargetPresenter()
public function getTargetPresenters()
{
if ($this->flags & self::ONE_WAY) {
return FALSE;
return array();
}

$m = $this->metadata;
Expand All @@ -689,14 +688,14 @@ public function getTargetPresenter()
if (isset($m[self::MODULE_KEY]['fixity']) && $m[self::MODULE_KEY]['fixity'] === self::CONSTANT) {
$module = $m[self::MODULE_KEY][self::VALUE] . ':';
} else {
return NULL;
return;

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Jan 26, 2015

Contributor

Its better to write return NULL because now you are returning void and that is semantically different. You should never mix returning void with returning a value.

This comment has been minimized.

Copy link
@dg

dg Jan 26, 2015

Author Member

On the other side, return NULL indicates that programmer doesn't understand PHP well enough.

This comment has been minimized.

Copy link
@Majkl578

Majkl578 Jan 26, 2015

Contributor

return NULL is more explicit in non-void functions. Agreed with @JanTvrdik.

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Jan 26, 2015

Contributor

I've seen (and written myself) return NULL countless times and not once have I though that the guy who wrote it does not understand PHP.

}
}

if (isset($m[self::PRESENTER_KEY]['fixity']) && $m[self::PRESENTER_KEY]['fixity'] === self::CONSTANT) {
return $module . $m[self::PRESENTER_KEY][self::VALUE];
return array($module . $m[self::PRESENTER_KEY][self::VALUE]);
}
return NULL;
return;
}


Expand Down
14 changes: 3 additions & 11 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,14 @@ public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\U
$routes['*'] = array();

foreach ($this as $route) {
$presenter = $route instanceof Route ? $route->getTargetPresenter() : NULL;
$presenters = $route instanceof Route && is_array($tmp = $route->getTargetPresenters())
? $tmp : array_keys($routes);

if ($presenter === FALSE) {
continue;
}

if (is_string($presenter)) {
foreach ($presenters as $presenter) {
if (!isset($routes[$presenter])) {
$routes[$presenter] = $routes['*'];
}
$routes[$presenter][] = $route;

} else {
foreach ($routes as $id => $foo) {
$routes[$id][] = $route;
}
}
}

Expand Down

0 comments on commit 032d6b4

Please sign in to comment.