 ylvarw    /
                    module
                      ylvarw    /
                    module
                
                            | 1 | <?php | ||
| 2 | /** | ||
| 3 | * Routes to ease development and debugging. | ||
| 4 | */ | ||
| 5 | return [ | ||
| 6 | // Path where to mount the routes, is added to each route path. | ||
| 7 | "mount" => "dev", | ||
| 8 | |||
| 9 | // All routes in order | ||
| 10 | "routes" => [ | ||
| 11 | [ | ||
| 12 | "info" => "Development and debugging information.", | ||
| 13 | "path" => "", | ||
| 14 |             "handler" => function ($di) { | ||
| 0 ignored issues–
                            show | |||
| 15 | echo <<<EOD | ||
| 16 | <h1>Anax development utilities</h1> | ||
| 17 | |||
| 18 | <p>Here is a set of utilities to use when learning, developing, testing and debugging Anax.</p> | ||
| 19 | |||
| 20 | <ul> | ||
| 21 | <li><a href="di">DI (show loaded services in \$di)</a></li> | ||
| 22 | <li><a href="request">Request (show details on current request)</a></li> | ||
| 23 | <li><a href="router">Router (show loaded routes)</a></li> | ||
| 24 | <li><a href="session">Session (show session data)</a></li> | ||
| 25 | </ul> | ||
| 26 | EOD; | ||
| 27 | return true; | ||
| 28 | }, | ||
| 29 | ], | ||
| 30 | [ | ||
| 31 | "info" => "DI (show loaded services in \$di).", | ||
| 32 | "path" => "di", | ||
| 33 |             "handler" => function ($di) { | ||
| 34 | $services = $di->getServices(); | ||
| 35 | $activeServices = $di->getActiveServices(); | ||
| 36 | $items = ""; | ||
| 37 |                 foreach ($services as $service) { | ||
| 38 | $active = in_array($service, $activeServices); | ||
| 39 | $boldStart = $active ? "<b>" : null; | ||
| 40 | $boldEnd = $active ? "<b>" : null; | ||
| 41 |                     $items .= "<li>${boldStart}${service}${boldEnd}</li>"; | ||
| 42 | }; | ||
| 43 | |||
| 44 | echo <<<EOD | ||
| 45 | <h1>DI and services</h1> | ||
| 46 | |||
| 47 | <p>These services are loaded into \$di, bold services are activated. | ||
| 48 | |||
| 49 | <ul> | ||
| 50 | $items | ||
| 51 | </ul> | ||
| 52 | EOD; | ||
| 53 | return true; | ||
| 54 | }, | ||
| 55 | ], | ||
| 56 | [ | ||
| 57 | "info" => "Request (show details on current request)", | ||
| 58 | "path" => "request", | ||
| 59 |             "handler" => function ($di) { | ||
| 60 |                 $request = $di->get("request"); | ||
| 61 |                 $routeParts = "[ " . implode(", ", $request->getRouteParts()) . " ]"; | ||
| 62 | |||
| 63 | echo <<<EOD | ||
| 64 | <h1>Request</h1> | ||
| 65 | |||
| 66 | <p>Here are details on the current request.</p> | ||
| 67 | |||
| 68 | <table> | ||
| 69 | <tr> | ||
| 70 | <th>Method</th> | ||
| 71 | <th>Result</th> | ||
| 72 | </tr> | ||
| 73 | <tr> | ||
| 74 | <td><code>getCurrentUrl()</code></td> | ||
| 75 |         <td><code>{$request->getCurrentUrl()}</code></td> | ||
| 76 | </tr> | ||
| 77 | <tr> | ||
| 78 | <td><code>getMethod()</code></td> | ||
| 79 |         <td><code>{$request->getMethod()}</code></td> | ||
| 80 | </tr> | ||
| 81 | <tr> | ||
| 82 | <td><code>getSiteUrl()</code></td> | ||
| 83 |         <td><code>{$request->getSiteUrl()}</code></td> | ||
| 84 | </tr> | ||
| 85 | <tr> | ||
| 86 | <td><code>getBaseUrl()</code></td> | ||
| 87 |         <td><code>{$request->getBaseUrl()}</code></td> | ||
| 88 | </tr> | ||
| 89 | <tr> | ||
| 90 | <td><code>getScriptName()</code></td> | ||
| 91 |         <td><code>{$request->getScriptName()}</code></td> | ||
| 92 | </tr> | ||
| 93 | <tr> | ||
| 94 | <td><code>getRoute()</code></td> | ||
| 95 |         <td><code>{$request->getRoute()}</code></td> | ||
| 96 | </tr> | ||
| 97 | <tr> | ||
| 98 | <td><code>getRouteParts()</code></td> | ||
| 99 | <td><code>$routeParts</code></td> | ||
| 100 | </tr> | ||
| 101 | </table> | ||
| 102 | EOD; | ||
| 103 | return true; | ||
| 104 | }, | ||
| 105 | ], | ||
| 106 | [ | ||
| 107 | "info" => "Router (show loaded routes)", | ||
| 108 | "path" => "router", | ||
| 109 |             "handler" => function ($di) { | ||
| 110 |                 $router = $di->get("router"); | ||
| 111 | |||
| 112 | $routes = ""; | ||
| 113 |                 foreach ($router->getAll() as $route) { | ||
| 114 | $routes .= <<<EOD | ||
| 115 | <tr> | ||
| 116 |     <td><code>"{$route->getAbsolutePath()}"</code></td> | ||
| 117 |     <td><code>{$route->getRequestMethod()}</code></td> | ||
| 118 |     <td>{$route->getInfo()}</td> | ||
| 119 | </tr> | ||
| 120 | EOD; | ||
| 121 | } | ||
| 122 | |||
| 123 | $internal = ""; | ||
| 124 |                 foreach ($router->getInternal() as $route) { | ||
| 125 | $internal .= <<<EOD | ||
| 126 | <tr> | ||
| 127 |     <td><code>"{$route->getAbsolutePath()}"</code></td> | ||
| 128 |     <td>{$route->getInfo()}</td> | ||
| 129 | </tr> | ||
| 130 | EOD; | ||
| 131 | } | ||
| 132 | |||
| 133 | echo <<<EOD | ||
| 134 | <h1>Router</h1> | ||
| 135 | |||
| 136 | <p>The following routes are loaded:</p> | ||
| 137 | |||
| 138 | <table> | ||
| 139 | <tr><th>Path</th><th>Method</th><th>Description</th></tr> | ||
| 140 | $routes | ||
| 141 | </table> | ||
| 142 | |||
| 143 | <p>The following internal routes are loaded:</p> | ||
| 144 | |||
| 145 | <table> | ||
| 146 | <tr><th>Path</th><th>Description</th></tr> | ||
| 147 | $internal | ||
| 148 | </table> | ||
| 149 | EOD; | ||
| 150 | return true; | ||
| 151 | }, | ||
| 152 | ], | ||
| 153 | [ | ||
| 154 | "info" => "Session (show session data).", | ||
| 155 | "path" => "session", | ||
| 156 |             "handler" => function ($di) { | ||
| 157 | $mount = "session/"; | ||
| 158 |                 $session = $di->get("session"); | ||
| 159 | $data = print_r($session->__debugInfo(), 1); | ||
| 160 | |||
| 161 | echo <<<EOD | ||
| 162 | <h1>Session</h1> | ||
| 163 | |||
| 164 | <p>The session contains the following data.</p> | ||
| 165 | |||
| 166 | <pre>$data</pre> | ||
| 167 | |||
| 168 | <p> | ||
| 169 |     <a href="${mount}increment">Add to session and increment<a> | | ||
| 170 |     <a href="${mount}destroy">Destroy session<a> | ||
| 171 | </p> | ||
| 172 | EOD; | ||
| 173 | return true; | ||
| 174 | }, | ||
| 175 | ], | ||
| 176 | [ | ||
| 177 | "info" => "Add +1 to session.", | ||
| 178 | "path" => "session/increment", | ||
| 179 |             "handler" => function ($di) { | ||
| 180 | echo "<h1>Session increment</h1>\n"; | ||
| 181 |                 $session = $di->get("session"); | ||
| 182 |                 $number = $session->get("number", 0); | ||
| 183 |                 $session->set("number", $number + 1); | ||
| 184 | var_dump($session); | ||
| 0 ignored issues–
                            show | |||
| 185 | return "Reload page to increment 'number' in the session."; | ||
| 186 | }, | ||
| 187 | ], | ||
| 188 | [ | ||
| 189 | "info" => "Destroy the session.", | ||
| 190 | "path" => "session/destroy", | ||
| 191 |             "handler" => function ($di) { | ||
| 192 | echo "<h1>Session destroy</h1>\n"; | ||
| 193 |                 $session = $di->get("session"); | ||
| 194 | var_dump($session); | ||
| 0 ignored issues–
                            show | |||
| 195 | $session->destroy(); | ||
| 196 | var_dump($session); | ||
| 197 | return "The session was destroyed."; | ||
| 198 | }, | ||
| 199 | ], | ||
| 200 | ] | ||
| 201 | ]; | ||
| 202 | 
 
                                
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.