colored_routes_print.md
· 3.9 KiB · Markdown
Неформатований
Вот переписанная функция с использованием `match` (доступен в PHP 8.0+), которая возвращает стили для HTTP-методов:
### **1. Функция `getMethodColor` с `match`**
```php
function getMethodColor(string $method): string
{
return match(strtoupper($method)) {
'GET' => 'background: #E6F7FF; color: #003366;',
'POST' => 'background: #E8F5E9; color: #1B5E20;',
'PUT',
'PATCH' => 'background: #FFF3E0; color: #E65100;', // Один стиль для PUT и PATCH
'DELETE' => 'background: #FFEBEE; color: #C62828;',
default => 'background: #F5F5F5; color: #212121;'
};
}
```
### **2. Полный пример таблицы с `match`**
```php
function getRoutingTable(array $routingRules): string
{
$table = "<table border='1' cellpadding='5' cellspacing='0' style='width:100%; border-collapse: collapse;'>";
$table .= "<thead><tr style='background: #f0f0f0;'>
<th>Method + Route</th>
<th>Handler</th>
<th>Name</th>
<th>Before Middlewares</th>
<th>After Middlewares</th>
</tr></thead><tbody>";
foreach ($routingRules as $route) {
$method = $route['httpMethod'];
$style = getMethodColor($method);
$handler = match(true) {
is_array($route['handler']) && count($route['handler']) === 2
=> "{$route['handler'][0]}@{$route['handler'][1]}",
$route['handler'] instanceof Closure
=> 'Closure',
isset($route['handler']['__invoke'])
=> 'Invokable Class',
default => 'Unknown'
};
$table .= "<tr style='{$style}'>
<td><strong>{$method}</strong> {$route['route']}</td>
<td>{$handler}</td>
<td>{$route['name'] ?? 'NULL'}</td>
<td>" . formatMiddlewares($route['middlewares']['before']) . "</td>
<td>" . formatMiddlewares($route['middlewares']['after']) . "</td>
</tr>";
}
$table .= "</tbody></table>";
return $table;
}
// Вспомогательная функция для форматирования middleware
function formatMiddlewares(iterable $middlewares): string
{
$result = [];
foreach ($middlewares as $mw) {
if (is_array($mw) && count($mw) === 2) {
$result[] = "{$mw[0]}@{$mw[1]}";
}
}
return $result ? implode('<br>', $result) : 'None';
}
```
### **Ключевые улучшения**:
1. **`match` для HTTP-методов**:
- Четкое сопоставление значений без `break`.
- Группировка `PUT` и `PATCH` в один стиль.
2. **`match` для определения типа handler**:
- Заменил цепочку `if-else` на более читаемый `match(true)`.
3. **Дополнительные стили**:
- Улучшено оформление таблицы (границы, отступы).
- Жирный шрифт для HTTP-метода.
4. **Вспомогательная функция**:
- `formatMiddlewares()` для единообразного вывода middleware.
### **Пример вывода**:
| Method + Route | Handler | Name | Before Middlewares | After Middlewares |
|------------------------------|----------------------------------|------------|--------------------------|-------------------|
| **GET** /api/users | UserController@index | users.list | AuthMiddleware | None |
| **POST** /api/users | UserController@store | NULL | AuthMiddleware, CSRF | LogMiddleware |
Такой код лучше соответствует современным стандартам PHP (8.0+) и улучшает читаемость.
Вот переписанная функция с использованием match
(доступен в PHP 8.0+), которая возвращает стили для HTTP-методов:
1. Функция getMethodColor
с match
function getMethodColor(string $method): string
{
return match(strtoupper($method)) {
'GET' => 'background: #E6F7FF; color: #003366;',
'POST' => 'background: #E8F5E9; color: #1B5E20;',
'PUT',
'PATCH' => 'background: #FFF3E0; color: #E65100;', // Один стиль для PUT и PATCH
'DELETE' => 'background: #FFEBEE; color: #C62828;',
default => 'background: #F5F5F5; color: #212121;'
};
}
2. Полный пример таблицы с match
function getRoutingTable(array $routingRules): string
{
$table = "<table border='1' cellpadding='5' cellspacing='0' style='width:100%; border-collapse: collapse;'>";
$table .= "<thead><tr style='background: #f0f0f0;'>
<th>Method + Route</th>
<th>Handler</th>
<th>Name</th>
<th>Before Middlewares</th>
<th>After Middlewares</th>
</tr></thead><tbody>";
foreach ($routingRules as $route) {
$method = $route['httpMethod'];
$style = getMethodColor($method);
$handler = match(true) {
is_array($route['handler']) && count($route['handler']) === 2
=> "{$route['handler'][0]}@{$route['handler'][1]}",
$route['handler'] instanceof Closure
=> 'Closure',
isset($route['handler']['__invoke'])
=> 'Invokable Class',
default => 'Unknown'
};
$table .= "<tr style='{$style}'>
<td><strong>{$method}</strong> {$route['route']}</td>
<td>{$handler}</td>
<td>{$route['name'] ?? 'NULL'}</td>
<td>" . formatMiddlewares($route['middlewares']['before']) . "</td>
<td>" . formatMiddlewares($route['middlewares']['after']) . "</td>
</tr>";
}
$table .= "</tbody></table>";
return $table;
}
// Вспомогательная функция для форматирования middleware
function formatMiddlewares(iterable $middlewares): string
{
$result = [];
foreach ($middlewares as $mw) {
if (is_array($mw) && count($mw) === 2) {
$result[] = "{$mw[0]}@{$mw[1]}";
}
}
return $result ? implode('<br>', $result) : 'None';
}
Ключевые улучшения:
-
match
для HTTP-методов:- Четкое сопоставление значений без
break
. - Группировка
PUT
иPATCH
в один стиль.
- Четкое сопоставление значений без
-
match
для определения типа handler:- Заменил цепочку
if-else
на более читаемыйmatch(true)
.
- Заменил цепочку
-
Дополнительные стили:
- Улучшено оформление таблицы (границы, отступы).
- Жирный шрифт для HTTP-метода.
-
Вспомогательная функция:
formatMiddlewares()
для единообразного вывода middleware.
Пример вывода:
Method + Route | Handler | Name | Before Middlewares | After Middlewares |
---|---|---|---|---|
GET /api/users | UserController@index | users.list | AuthMiddleware | None |
POST /api/users | UserController@store | NULL | AuthMiddleware, CSRF | LogMiddleware |
Такой код лучше соответствует современным стандартам PHP (8.0+) и улучшает читаемость.
dump.md
· 26 KiB · Markdown
Неформатований
```
var_dump( AppRouter::getRoutingRules() );
Печатает вот такой код:
array(23) {
["GET / Closure(30-32)="]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(1) "/"
["handler"]=>
object(Closure)#46 (0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#47 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#48 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(30)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/login/ \App\App\Controllers\AuthController@form_login"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(12) "/auth/login/"
["handler"]=>
array(2) {
[0]=>
string(30) "App\Controllers\AuthController"
[1]=>
string(10) "form_login"
}
["namespace"]=>
string(4) "\App"
["name"]=>
string(10) "form_login"
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#49 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#50 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(35)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /auth/login/ \App\App\Controllers\AuthController@callback_login"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(12) "/auth/login/"
["handler"]=>
array(2) {
[0]=>
string(30) "App\Controllers\AuthController"
[1]=>
string(14) "callback_login"
}
["namespace"]=>
string(4) "\App"
["name"]=>
string(14) "callback_login"
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#51 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#52 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(36)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/logout/ \App\App\Controllers\AuthController@callback_logout"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(13) "/auth/logout/"
["handler"]=>
array(2) {
[0]=>
string(30) "App\Controllers\AuthController"
[1]=>
string(15) "callback_logout"
}
["namespace"]=>
string(4) "\App"
["name"]=>
string(15) "callback_logout"
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#53 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#54 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(37)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/register/ \App\827f47bf8b69fee30d84e03917576c65@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(15) "/auth/register/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#55 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#56 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(39)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /auth/register/ \App\827f47bf8b69fee30d84e03917576c65@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(15) "/auth/register/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#57 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#58 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(40)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/remember/ \App\7141310c9236cccbb0f9e4515c1e191e@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(15) "/auth/remember/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#59 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#60 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(42)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /auth/remember/ \App\7141310c9236cccbb0f9e4515c1e191e@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(15) "/auth/remember/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#61 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#62 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(43)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/ \App\e9021b37cdf3ddfd7edbf584f708e2a2@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(15) "/admin/taverns/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#64 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#65 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(48)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/add/ \App\f01fcede504dbb43d8a159a4ca6a3cb5@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(19) "/admin/taverns/add/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#66 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#67 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(50)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/taverns/insert/ \App\8bda1a98077bd07178eb401f57a87c1b@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(22) "/admin/taverns/insert/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#68 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#69 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(51)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/edit/{id:\d+}/ \App\72fc6667fa06e13ce14274fa0b905010@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(29) "/admin/taverns/edit/{id:\d+}/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#70 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#71 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(52)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/taverns/update/ \App\cc8eeadf70d4736ea8e4ab02b684e558@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(22) "/admin/taverns/update/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#72 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#73 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(53)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/info/{id:\d+}/dishes \App\335b8ebb42b57cdde4ec70c5568a875b@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(35) "/admin/taverns/info/{id:\d+}/dishes"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#74 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#75 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(55)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/taverns/info/{id:\d+}/dishes \App\335b8ebb42b57cdde4ec70c5568a875b@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(35) "/admin/taverns/info/{id:\d+}/dishes"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#76 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#77 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(56)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/users/ \App\68db4d7a827260fd60e04f9641ad0ccb@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(13) "/admin/users/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#80 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#81 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(62)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/users/edit/{id:\d+}/ \App\51edff3d905ab95258129978fe4a8755@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(27) "/admin/users/edit/{id:\d+}/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#82 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#83 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(63)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/users/update/ \App\1e328d702d8266318ff6bb7fa9aa8de2@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(20) "/admin/users/update/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#84 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#85 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(64)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/users/delete/{id:\d+}/ \App\2dc117420c50d37684b28d29be5a525c@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(29) "/admin/users/delete/{id:\d+}/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#86 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#87 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(65)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/ \App\7e2ab5a5ee7c8ff02140bfbda1f9cde2@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(14) "/admin/dishes/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#88 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#89 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(70)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/view/ \App\493b4dff7f487593a373b373d252689e@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(19) "/admin/dishes/view/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#90 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#91 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(71)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/update/ \App\33b11307187ceac2d4e86e9551c85f29@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(21) "/admin/dishes/update/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#92 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#93 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(72)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/delete/ \App\c014cf502bf12c033826d5a5e9a6b02c@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(21) "/admin/dishes/delete/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#94 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#95 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(73)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
}
- after middlewares
```
Напиши мне функцию, которая будет возвращать таблицу с 5 столбцами:
- HTTP Method + route
- handler (closure или Class @ method)
- name
- before middlwares
var_dump( AppRouter::getRoutingRules() );
Печатает вот такой код:
array(23) {
["GET / Closure(30-32)="]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(1) "/"
["handler"]=>
object(Closure)#46 (0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#47 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#48 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(30)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/login/ \App\App\Controllers\AuthController@form_login"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(12) "/auth/login/"
["handler"]=>
array(2) {
[0]=>
string(30) "App\Controllers\AuthController"
[1]=>
string(10) "form_login"
}
["namespace"]=>
string(4) "\App"
["name"]=>
string(10) "form_login"
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#49 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#50 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(35)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /auth/login/ \App\App\Controllers\AuthController@callback_login"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(12) "/auth/login/"
["handler"]=>
array(2) {
[0]=>
string(30) "App\Controllers\AuthController"
[1]=>
string(14) "callback_login"
}
["namespace"]=>
string(4) "\App"
["name"]=>
string(14) "callback_login"
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#51 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#52 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(36)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/logout/ \App\App\Controllers\AuthController@callback_logout"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(13) "/auth/logout/"
["handler"]=>
array(2) {
[0]=>
string(30) "App\Controllers\AuthController"
[1]=>
string(15) "callback_logout"
}
["namespace"]=>
string(4) "\App"
["name"]=>
string(15) "callback_logout"
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#53 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#54 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(37)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/register/ \App\827f47bf8b69fee30d84e03917576c65@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(15) "/auth/register/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#55 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#56 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(39)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /auth/register/ \App\827f47bf8b69fee30d84e03917576c65@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(15) "/auth/register/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#57 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#58 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(40)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /auth/remember/ \App\7141310c9236cccbb0f9e4515c1e191e@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(15) "/auth/remember/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#59 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#60 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(42)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /auth/remember/ \App\7141310c9236cccbb0f9e4515c1e191e@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(15) "/auth/remember/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#61 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
["after"]=>
object(Arris\AppRouter\Stack)#62 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(43)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/ \App\e9021b37cdf3ddfd7edbf584f708e2a2@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(15) "/admin/taverns/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#64 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#65 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(48)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/add/ \App\f01fcede504dbb43d8a159a4ca6a3cb5@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(19) "/admin/taverns/add/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#66 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#67 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(50)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/taverns/insert/ \App\8bda1a98077bd07178eb401f57a87c1b@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(22) "/admin/taverns/insert/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#68 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#69 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(51)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/edit/{id:\d+}/ \App\72fc6667fa06e13ce14274fa0b905010@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(29) "/admin/taverns/edit/{id:\d+}/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#70 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#71 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(52)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/taverns/update/ \App\cc8eeadf70d4736ea8e4ab02b684e558@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(22) "/admin/taverns/update/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#72 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#73 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(53)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/taverns/info/{id:\d+}/dishes \App\335b8ebb42b57cdde4ec70c5568a875b@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(35) "/admin/taverns/info/{id:\d+}/dishes"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#74 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#75 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(55)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/taverns/info/{id:\d+}/dishes \App\335b8ebb42b57cdde4ec70c5568a875b@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(35) "/admin/taverns/info/{id:\d+}/dishes"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#76 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#77 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(56)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/users/ \App\68db4d7a827260fd60e04f9641ad0ccb@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(13) "/admin/users/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#80 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#81 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(62)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/users/edit/{id:\d+}/ \App\51edff3d905ab95258129978fe4a8755@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(27) "/admin/users/edit/{id:\d+}/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#82 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#83 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(63)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["POST /admin/users/update/ \App\1e328d702d8266318ff6bb7fa9aa8de2@__invoke"]=>
array(7) {
["httpMethod"]=>
string(4) "POST"
["route"]=>
string(20) "/admin/users/update/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#84 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#85 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(64)
["function"]=>
string(4) "post"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/users/delete/{id:\d+}/ \App\2dc117420c50d37684b28d29be5a525c@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(29) "/admin/users/delete/{id:\d+}/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#86 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#87 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(65)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/ \App\7e2ab5a5ee7c8ff02140bfbda1f9cde2@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(14) "/admin/dishes/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#88 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#89 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(70)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/view/ \App\493b4dff7f487593a373b373d252689e@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(19) "/admin/dishes/view/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#90 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#91 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(71)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/update/ \App\33b11307187ceac2d4e86e9551c85f29@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(21) "/admin/dishes/update/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#92 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#93 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(72)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
["GET /admin/dishes/delete/ \App\c014cf502bf12c033826d5a5e9a6b02c@__invoke"]=>
array(7) {
["httpMethod"]=>
string(3) "GET"
["route"]=>
string(21) "/admin/dishes/delete/"
["handler"]=>
array(0) {
}
["namespace"]=>
string(4) "\App"
["name"]=>
NULL
["middlewares"]=>
array(2) {
["before"]=>
object(Arris\AppRouter\Stack)#94 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(10) "check_auth"
}
[1]=>
array(2) {
[0]=>
string(30) "App\Middlewares\AuthMiddleware"
[1]=>
string(11) "check_admin"
}
}
}
["after"]=>
object(Arris\AppRouter\Stack)#95 (1) {
["stack":"Arris\AppRouter\Stack":private]=>
array(0) {
}
}
}
["backtrace"]=>
array(5) {
["file"]=>
string(43) "/var/www/dch_spb_breakfast/public/index.php"
["line"]=>
int(73)
["function"]=>
string(3) "get"
["class"]=>
string(15) "Arris\AppRouter"
["type"]=>
string(2) "::"
}
}
}
- after middlewares
Напиши мне функцию, которая будет возвращать таблицу с 5 столбцами:
- HTTP Method + route
- handler (closure или Class @ method)
- name
- before middlwares
getRoutingTable.md
· 2.0 KiB · Markdown
Неформатований
```php
function getRoutingTable(array $routingRules): string
{
$table = "<table border='1' cellpadding='5' cellspacing='0'>";
$table .= "<thead><tr>
<th>HTTP Method + Route</th>
<th>Handler</th>
<th>Name</th>
<th>Before Middlewares</th>
<th>After Middlewares</th>
</tr></thead><tbody>";
foreach ($routingRules as $route) {
// HTTP Method + Route
$methodRoute = "{$route['httpMethod']} {$route['route']}";
// Handler
$handler = '';
if (is_array($route['handler']) && count($route['handler']) === 2) {
$handler = "{$route['handler'][0]}@{$route['handler'][1]}";
} elseif ($route['handler'] instanceof Closure) {
$handler = 'Closure';
} elseif (isset($route['handler']['__invoke'])) {
$handler = 'Invokable Class';
}
// Name
$name = $route['name'] ?? 'NULL';
// Before Middlewares
$beforeMiddlewares = [];
foreach ($route['middlewares']['before'] as $middleware) {
if (is_array($middleware) && count($middleware) === 2) {
$beforeMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$beforeMiddlewaresStr = implode('<br>', $beforeMiddlewares) ?: 'None';
// After Middlewares
$afterMiddlewares = [];
foreach ($route['middlewares']['after'] as $middleware) {
if (is_array($middleware) {
$afterMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$afterMiddlewaresStr = implode('<br>', $afterMiddlewares) ?: 'None';
$table .= "<tr>
<td>{$methodRoute}</td>
<td>{$handler}</td>
<td>{$name}</td>
<td>{$beforeMiddlewaresStr}</td>
<td>{$afterMiddlewaresStr}</td>
</tr>";
}
$table .= "</tbody></table>";
return $table;
}
// Использование:
echo getRoutingTable(AppRouter::getRoutingRules());
```
function getRoutingTable(array $routingRules): string
{
$table = "<table border='1' cellpadding='5' cellspacing='0'>";
$table .= "<thead><tr>
<th>HTTP Method + Route</th>
<th>Handler</th>
<th>Name</th>
<th>Before Middlewares</th>
<th>After Middlewares</th>
</tr></thead><tbody>";
foreach ($routingRules as $route) {
// HTTP Method + Route
$methodRoute = "{$route['httpMethod']} {$route['route']}";
// Handler
$handler = '';
if (is_array($route['handler']) && count($route['handler']) === 2) {
$handler = "{$route['handler'][0]}@{$route['handler'][1]}";
} elseif ($route['handler'] instanceof Closure) {
$handler = 'Closure';
} elseif (isset($route['handler']['__invoke'])) {
$handler = 'Invokable Class';
}
// Name
$name = $route['name'] ?? 'NULL';
// Before Middlewares
$beforeMiddlewares = [];
foreach ($route['middlewares']['before'] as $middleware) {
if (is_array($middleware) && count($middleware) === 2) {
$beforeMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$beforeMiddlewaresStr = implode('<br>', $beforeMiddlewares) ?: 'None';
// After Middlewares
$afterMiddlewares = [];
foreach ($route['middlewares']['after'] as $middleware) {
if (is_array($middleware) {
$afterMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$afterMiddlewaresStr = implode('<br>', $afterMiddlewares) ?: 'None';
$table .= "<tr>
<td>{$methodRoute}</td>
<td>{$handler}</td>
<td>{$name}</td>
<td>{$beforeMiddlewaresStr}</td>
<td>{$afterMiddlewaresStr}</td>
</tr>";
}
$table .= "</tbody></table>";
return $table;
}
// Использование:
echo getRoutingTable(AppRouter::getRoutingRules());
getRoutingTableText.md
· 1.8 KiB · Markdown
Неформатований
```php
function getRoutingTableText(array $routingRules): string
{
$output = "HTTP Method + Route\tHandler\tName\tBefore Middlewares\tAfter Middlewares\n";
$output .= str_repeat("-", 150) . "\n";
foreach ($routingRules as $route) {
// HTTP Method + Route
$methodRoute = "{$route['httpMethod']} {$route['route']}";
// Handler
$handler = '';
if (is_array($route['handler']) && count($route['handler']) === 2) {
$handler = "{$route['handler'][0]}@{$route['handler'][1]}";
} elseif ($route['handler'] instanceof Closure) {
$handler = 'Closure';
} elseif (isset($route['handler']['__invoke'])) {
$handler = 'Invokable Class';
}
// Name
$name = $route['name'] ?? 'NULL';
// Before Middlewares
$beforeMiddlewares = [];
foreach ($route['middlewares']['before'] as $middleware) {
if (is_array($middleware) && count($middleware) === 2) {
$beforeMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$beforeMiddlewaresStr = implode(', ', $beforeMiddlewares) ?: 'None';
// After Middlewares
$afterMiddlewares = [];
foreach ($route['middlewares']['after'] as $middleware) {
if (is_array($middleware)) {
$afterMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$afterMiddlewaresStr = implode(', ', $afterMiddlewares) ?: 'None';
$output .= sprintf("%-40s %-40s %-15s %-30s %-30s\n",
$methodRoute,
$handler,
$name,
$beforeMiddlewaresStr,
$afterMiddlewaresStr
);
}
return $output;
}
// Использование:
echo getRoutingTableText(AppRouter::getRoutingRules());
```
function getRoutingTableText(array $routingRules): string
{
$output = "HTTP Method + Route\tHandler\tName\tBefore Middlewares\tAfter Middlewares\n";
$output .= str_repeat("-", 150) . "\n";
foreach ($routingRules as $route) {
// HTTP Method + Route
$methodRoute = "{$route['httpMethod']} {$route['route']}";
// Handler
$handler = '';
if (is_array($route['handler']) && count($route['handler']) === 2) {
$handler = "{$route['handler'][0]}@{$route['handler'][1]}";
} elseif ($route['handler'] instanceof Closure) {
$handler = 'Closure';
} elseif (isset($route['handler']['__invoke'])) {
$handler = 'Invokable Class';
}
// Name
$name = $route['name'] ?? 'NULL';
// Before Middlewares
$beforeMiddlewares = [];
foreach ($route['middlewares']['before'] as $middleware) {
if (is_array($middleware) && count($middleware) === 2) {
$beforeMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$beforeMiddlewaresStr = implode(', ', $beforeMiddlewares) ?: 'None';
// After Middlewares
$afterMiddlewares = [];
foreach ($route['middlewares']['after'] as $middleware) {
if (is_array($middleware)) {
$afterMiddlewares[] = "{$middleware[0]}@{$middleware[1]}";
}
}
$afterMiddlewaresStr = implode(', ', $afterMiddlewares) ?: 'None';
$output .= sprintf("%-40s %-40s %-15s %-30s %-30s\n",
$methodRoute,
$handler,
$name,
$beforeMiddlewaresStr,
$afterMiddlewaresStr
);
}
return $output;
}
// Использование:
echo getRoutingTableText(AppRouter::getRoutingRules());