Skip to content

Commit

Permalink
RoutingPanel: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 2, 2020
1 parent fee1365 commit 717bb5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class RoutingPanel implements Tracy\IBarPanel
/** @var Nette\Application\IPresenterFactory */
private $presenterFactory;

/** @var array */
/** @var \stdClass[] */
private $routers = [];

/** @var array|null */
Expand Down Expand Up @@ -85,7 +85,7 @@ public function getPanel(): string
$matched = $this->matched;
$routers = $this->routers;
$source = $this->source;
$hasModule = (bool) array_filter($routers, function (array $rq): string { return $rq['module']; });
$hasModule = (bool) array_filter($routers, function (\stdClass $rq): string { return $rq->module; });
$url = $this->httpRequest->getUrl();
$method = $this->httpRequest->getMethod();
require __DIR__ . '/templates/RoutingPanel.panel.phtml';
Expand Down Expand Up @@ -125,7 +125,7 @@ private function analyse(Routing\Router $router, string $module = ''): void
}
}

$this->routers[] = [
$this->routers[] = (object) [
'matched' => $matched,
'class' => get_class($router),
'defaults' => $router instanceof Routing\Route || $router instanceof Routing\SimpleRouter ? $router->getDefaults() : [],
Expand Down
16 changes: 8 additions & 8 deletions src/Bridges/ApplicationTracy/templates/RoutingPanel.panel.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,29 @@ use Tracy\Helpers;

<tbody>
<?php foreach ($routers as $router): ?>
<tr class="<?= $router['matched'] ?>">
<td><?= $router['matched'] === 'yes' ? '' : ($router['matched'] === 'may' ? '' : '') ?></td>
<tr class="<?= $router->matched ?>">
<td><?= $router->matched === 'yes' ? '' : ($router->matched === 'may' ? '' : '') ?></td>

<td><code title="<?= Helpers::escapeHtml($router['class']) ?>"><?= isset($router['mask']) ? str_replace(['/', '-'], ['<wbr>/', '<wbr>-'], Helpers::escapeHtml($router['mask'])) : str_replace('\\', '<wbr>\\', Helpers::escapeHtml($router['class'])) ?></code></td>
<td><code title="<?= Helpers::escapeHtml($router->class) ?>"><?= isset($router->mask) ? str_replace(['/', '-'], ['<wbr>/', '<wbr>-'], Helpers::escapeHtml($router->mask)) : str_replace('\\', '<wbr>\\', Helpers::escapeHtml($router->class)) ?></code></td>

<td><code>
<?php foreach ($router['defaults'] as $key => $value): ?>
<?php foreach ($router->defaults as $key => $value): ?>
<?= Helpers::escapeHtml($key), '&nbsp;=&nbsp;', is_string($value) ? Helpers::escapeHtml($value) . '<br />' : Dumper::toHtml($value, [Dumper::COLLAPSE => true, Dumper::LIVE => true]) ?>
<?php endforeach ?>
</code></td>

<?php if ($hasModule): ?><td><code><?= Helpers::escapeHtml($router['module']) ?></code></td><?php endif ?>
<?php if ($hasModule): ?><td><code><?= Helpers::escapeHtml($router->module) ?></code></td><?php endif ?>

<td><?php if ($router['params']): ?><code>
<?php $params = $router['params']; ?>
<td><?php if ($router->params): ?><code>
<?php $params = $router->params; ?>
<?php if (isset($params[Presenter::PRESENTER_KEY])): ?>
<strong><?= Helpers::escapeHtml($params['presenter'] . ':' . (isset($params[Presenter::ACTION_KEY]) ? $params[Presenter::ACTION_KEY] : Presenter::DEFAULT_ACTION)) ?></strong><br />
<?php unset($params[Presenter::PRESENTER_KEY], $params[Presenter::ACTION_KEY]) ?>
<?php endif ?>
<?php foreach ($params as $key => $value): ?>
<?= Helpers::escapeHtml($key), '&nbsp;=&nbsp;', is_string($value) ? Helpers::escapeHtml($value) . '<br />' : Dumper::toHtml($value, [Dumper::COLLAPSE => true, Dumper::LIVE => true]) ?>
<?php endforeach ?>
</code><?php elseif ($router['error']): ?><strong><?= Helpers::escapeHtml($router['error']->getMessage()) ?></strong><?php endif ?></td>
</code><?php elseif ($router->error): ?><strong><?= Helpers::escapeHtml($router->error->getMessage()) ?></strong><?php endif ?></td>
</tr>
<?php endforeach ?>
</tbody>
Expand Down

0 comments on commit 717bb5c

Please sign in to comment.