~ubuntu-branches/debian/experimental/php-nette/experimental

« back to all changes in this revision

Viewing changes to Nette-2.1.0RC/Nette/Application/Diagnostics/RoutingPanel.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2013-11-30 08:47:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131130084754-4udf1xsu9085tnfc
Tags: 2.1.0~rc-1
* New upstream branch
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * This file is part of the Nette Framework (http://nette.org)
 
5
 *
 
6
 * Copyright (c) 2004 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, // used in templates
 
17
        Nette\Diagnostics\Dumper;
 
18
 
 
19
 
 
20
/**
 
21
 * Routing debugger for Debug Bar.
 
22
 *
 
23
 * @author     David Grudl
 
24
 */
 
25
class RoutingPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
 
26
{
 
27
        /** @var Nette\Application\IRouter */
 
28
        private $router;
 
29
 
 
30
        /** @var Nette\Http\IRequest */
 
31
        private $httpRequest;
 
32
 
 
33
        /** @var array */
 
34
        private $routers = array();
 
35
 
 
36
        /** @var Nette\Application\Request */
 
37
        private $request;
 
38
 
 
39
 
 
40
        public static function initializePanel(Nette\Application\Application $application)
 
41
        {
 
42
                Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(function($e) use ($application) {
 
43
                        return $e ? NULL : array(
 
44
                                'tab' => 'Nette Application',
 
45
                                'panel' => '<h3>Requests</h3>' . Dumper::toHtml($application->getRequests())
 
46
                                        . '<h3>Presenter</h3>' . Dumper::toHtml($application->getPresenter())
 
47
                        );
 
48
                });
 
49
        }
 
50
 
 
51
 
 
52
        public function __construct(Nette\Application\IRouter $router, Nette\Http\IRequest $httpRequest)
 
53
        {
 
54
                $this->router = $router;
 
55
                $this->httpRequest = $httpRequest;
 
56
        }
 
57
 
 
58
 
 
59
        /**
 
60
         * Renders tab.
 
61
         * @return string
 
62
         */
 
63
        public function getTab()
 
64
        {
 
65
                $this->analyse($this->router);
 
66
                ob_start();
 
67
                require __DIR__ . '/templates/RoutingPanel.tab.phtml';
 
68
                return ob_get_clean();
 
69
        }
 
70
 
 
71
 
 
72
        /**
 
73
         * Renders panel.
 
74
         * @return string
 
75
         */
 
76
        public function getPanel()
 
77
        {
 
78
                ob_start();
 
79
                require __DIR__ . '/templates/RoutingPanel.panel.phtml';
 
80
                return ob_get_clean();
 
81
        }
 
82
 
 
83
 
 
84
        /**
 
85
         * Analyses simple route.
 
86
         * @param  Nette\Application\IRouter
 
87
         * @return void
 
88
         */
 
89
        private function analyse($router, $module = '')
 
90
        {
 
91
                if ($router instanceof Routers\RouteList) {
 
92
                        foreach ($router as $subRouter) {
 
93
                                $this->analyse($subRouter, $module . $router->getModule());
 
94
                        }
 
95
                        return;
 
96
                }
 
97
 
 
98
                $matched = 'no';
 
99
                $request = $router->match($this->httpRequest);
 
100
                if ($request) {
 
101
                        $request->setPresenterName($module . $request->getPresenterName());
 
102
                        $matched = 'may';
 
103
                        if (empty($this->request)) {
 
104
                                $this->request = $request;
 
105
                                $matched = 'yes';
 
106
                        }
 
107
                }
 
108
 
 
109
                $this->routers[] = array(
 
110
                        'matched' => $matched,
 
111
                        'class' => get_class($router),
 
112
                        'defaults' => $router instanceof Routers\Route || $router instanceof Routers\SimpleRouter ? $router->getDefaults() : array(),
 
113
                        'mask' => $router instanceof Routers\Route ? $router->getMask() : NULL,
 
114
                        'request' => $request,
 
115
                        'module' => rtrim($module, ':')
 
116
                );
 
117
        }
 
118
 
 
119
}