Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface IRouteMeta define API for RoutingPanel. #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions src/Application/IRouteMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/

namespace Nette\Application;


/**
* Define API for RoutingPanel.
*/
interface IRouteMeta
{

/**
* Return route mask.
* @return string
*/
function getMask();

/**
* Returns default values.
* @return array
*/
function getDefaults();

}
2 changes: 1 addition & 1 deletion src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* The bidirectional route is responsible for mapping
* HTTP request to a Request object for dispatch and vice-versa.
*/
class Route extends Nette\Object implements Application\IRouter
class Route extends Nette\Object implements Application\IRouter, Application\IRouteMeta
{
const PRESENTER_KEY = 'presenter';
const MODULE_KEY = 'module';
Expand Down
11 changes: 10 additions & 1 deletion src/Application/Routers/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* The bidirectional route for trivial routing via query parameters.
*/
class SimpleRouter extends Nette\Object implements Application\IRouter
class SimpleRouter extends Nette\Object implements Application\IRouter, Application\IRouteMeta
{
const PRESENTER_KEY = 'presenter';
const MODULE_KEY = 'module';
Expand Down Expand Up @@ -142,4 +142,13 @@ public function getFlags()
return $this->flags;
}

/**
* Info how url looks like.
* @return string
*/
public function getMask()
{
return '?presenter=<presenter>[&action=<action>]';
}

}
5 changes: 3 additions & 2 deletions src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Nette\Bridges\ApplicationTracy;

use Nette;
use Nette\Application;
use Nette\Application\Routers;
use Nette\Application\UI\Presenter;
use Tracy;
Expand Down Expand Up @@ -119,8 +120,8 @@ private function analyse($router, $module = '')
$this->routers[] = [
'matched' => $matched,
'class' => get_class($router),
'defaults' => $router instanceof Routers\Route || $router instanceof Routers\SimpleRouter ? $router->getDefaults() : [],
'mask' => $router instanceof Routers\Route ? $router->getMask() : NULL,
'defaults' => $router instanceof Application\IRouteMeta ? $router->getDefaults() : [],
'mask' => $router instanceof Application\IRouteMeta ? $router->getMask() : NULL,
'request' => $request,
'module' => rtrim($module, ':'),
];
Expand Down