Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • RoutingPanel
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Application\Diagnostics;
 13: 
 14: use Nette,
 15:     Nette\Application\Routers,
 16:     Nette\Application\UI\Presenter, // templates
 17:     Nette\Diagnostics\Debugger;
 18: 
 19: 
 20: 
 21: /**
 22:  * Routing debugger for Debug Bar.
 23:  *
 24:  * @author     David Grudl
 25:  */
 26: class RoutingPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
 27: {
 28:     /** @var Nette\Application\IRouter */
 29:     private $router;
 30: 
 31:     /** @var Nette\Http\IRequest */
 32:     private $httpRequest;
 33: 
 34:     /** @var array */
 35:     private $routers = array();
 36: 
 37:     /** @var Nette\Application\Request */
 38:     private $request;
 39: 
 40: 
 41: 
 42:     public static function initialize(Nette\Application\Application $application, Nette\Http\IRequest $httpRequest)
 43:     {
 44:         Debugger::$bar->addPanel(new self($application->getRouter(), $httpRequest));
 45:         Debugger::$blueScreen->addPanel(function($e) use ($application) {
 46:             if ($e === NULL) {
 47:                 return array(
 48:                     'tab' => 'Nette Application',
 49:                     'panel' => '<h3>Requests</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getRequests())
 50:                         . '<h3>Presenter</h3>' . Nette\Diagnostics\Helpers::clickableDump($application->getPresenter())
 51:                 );
 52:             }
 53:         });
 54:     }
 55: 
 56: 
 57: 
 58:     public function __construct(Nette\Application\IRouter $router, Nette\Http\IRequest $httpRequest)
 59:     {
 60:         $this->router = $router;
 61:         $this->httpRequest = $httpRequest;
 62:     }
 63: 
 64: 
 65: 
 66:     /**
 67:      * Renders tab.
 68:      * @return string
 69:      */
 70:     public function getTab()
 71:     {
 72:         $this->analyse($this->router);
 73:         ob_start();
 74:         require __DIR__ . '/templates/RoutingPanel.tab.phtml';
 75:         return ob_get_clean();
 76:     }
 77: 
 78: 
 79: 
 80:     /**
 81:      * Renders panel.
 82:      * @return string
 83:      */
 84:     public function getPanel()
 85:     {
 86:         ob_start();
 87:         require __DIR__ . '/templates/RoutingPanel.panel.phtml';
 88:         return ob_get_clean();
 89:     }
 90: 
 91: 
 92: 
 93:     /**
 94:      * Analyses simple route.
 95:      * @param  Nette\Application\IRouter
 96:      * @return void
 97:      */
 98:     private function analyse($router)
 99:     {
100:         if ($router instanceof Routers\RouteList) {
101:             foreach ($router as $subRouter) {
102:                 $this->analyse($subRouter);
103:             }
104:             return;
105:         }
106: 
107:         $request = $router->match($this->httpRequest);
108:         $matched = $request === NULL ? 'no' : 'may';
109:         if ($request !== NULL && empty($this->request)) {
110:             $this->request = $request;
111:             $matched = 'yes';
112:         }
113: 
114:         $this->routers[] = array(
115:             'matched' => $matched,
116:             'class' => get_class($router),
117:             'defaults' => $router instanceof Routers\Route || $router instanceof Routers\SimpleRouter ? $router->getDefaults() : array(),
118:             'mask' => $router instanceof Routers\Route ? $router->getMask() : NULL,
119:             'request' => $request,
120:         );
121:     }
122: 
123: }
124: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0