├── LICENSE.md ├── README.md ├── composer.json ├── screenshots └── route-list.png └── src ├── Console └── Commands │ └── RouteListCommand.php └── LumenRouteListServiceProvider.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Saddam H 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Lumen Route List 2 | =================== 3 | 4 | 5 | This package will help to display all the registered route list like laravel. 6 | 7 | #### This package is no longer maintained :( use this package [appzcoder/lumen-route-list](https://github.com/appzcoder/lumen-route-list) 8 | 9 | ---------- 10 | 11 | Installation 12 | ------------- 13 | Via Composer 14 | 15 | ``` bash 16 | $ composer require thedevsaddam/lumen-route-list 17 | ``` 18 | Install manually (add the line to composer.json file) 19 | ``` bash 20 | "thedevsaddam/lumen-route-list": "^1.0" 21 | ``` 22 | Then open your terminal and hit the command 23 | ```bash 24 | composer update 25 | ``` 26 | Open bootstrap/app.php and add the line below 27 | 28 | ```php 29 | $app->register(\Thedevsaddam\LumenRouteList\LumenRouteListServiceProvider::class); 30 | ``` 31 | 32 |
33 | 34 | ### **Uses** 35 | 1. Run `php artisan route:list` to display the route list 36 | 1. Inorder to filter routes use `php artisan route:list --method=searchKeyword --uri=searchKeyword` 37 | 1. To display in reverse order use `--reverse` or `-r` 38 | 39 | Filtering example given below: 40 | ```bash 41 | php artisan route:list --method=post 42 | #The above example will filter all the routes with post method# 43 | or 44 | php artisan route:list --name=users 45 | #The above example will filter all the routes which name contains *user* keyword# 46 | or 47 | php artisan route:list --name=users --method=get --uri=api/v1 48 | #This above example will filter all the routes where name matches users, method matches get and uri matches api/v1 49 | or to display in reverse order use 50 | php artisan route:list --name=users -r 51 | ``` 52 | 53 | ![route list like laravel](https://raw.githubusercontent.com/thedevsaddam/lumen-route-list/master/screenshots/route-list.png) 54 | 55 | 56 | ### **License** 57 | The **lumen-route-list** is a open-source software licensed under the [MIT License](LICENSE.md). 58 | 59 | _Thank you :)_ 60 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thedevsaddam/lumen-route-list", 3 | "description": "Display all the registered route list like laravel", 4 | "type": "package", 5 | "keywords": [ 6 | "thedevsaddam", 7 | "lumen", 8 | "lumen-route-list", 9 | "route-list", 10 | "routes", 11 | "lumen routes list" 12 | ], 13 | "homepage": "https://github.com/thedevsaddam/lumen-route-list", 14 | "license": "MIT", 15 | "authors": [ 16 | { 17 | "name": "Saddam Hossain", 18 | "email": "thedevsaddam@gmail.com", 19 | "role": "Developer" 20 | } 21 | ], 22 | "minimum-stability": "stable", 23 | "require": {}, 24 | "autoload": { 25 | "psr-4": { 26 | "Thedevsaddam\\LumenRouteList\\":"src" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /screenshots/route-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thedevsaddam/lumen-route-list/9954e2e1a6c2afdea9d577107555ab437b371e22/screenshots/route-list.png -------------------------------------------------------------------------------- /src/Console/Commands/RouteListCommand.php: -------------------------------------------------------------------------------- 1 | displayRoutes(); 43 | return; 44 | } 45 | 46 | /** 47 | * Display the routes in console 48 | * @return bool 49 | */ 50 | public function displayRoutes() 51 | { 52 | $headers = ['Method', 'URI', 'Name', 'Action', 'Middleware', 'Map To']; 53 | $this->generateRoutes(); 54 | $this->applyFilters(); 55 | if (!$this->routes) { 56 | $this->warn('No routes found!'); 57 | return false; 58 | } 59 | //change the reverse order if command contains reverse command 60 | $str = ''; 61 | if ($this->option('reverse')) { 62 | rsort($this->routes); 63 | $str = '. Displayed in reverse order'; 64 | } 65 | $this->info("Route found: " . count($this->routes) . $str); 66 | $this->table($headers, $this->routes); 67 | } 68 | 69 | /** 70 | * Generate the formatted routes array 71 | * @return bool 72 | */ 73 | public function generateRoutes() 74 | { 75 | $routes = property_exists(app(), 'router')? app()->router->getRoutes() : app()->getRoutes(); 76 | foreach ($routes as $route) { 77 | array_push($this->routes, [ 78 | 'method' => $route['method'], 79 | 'uri' => $route['uri'], 80 | 'name' => $this->getRouteName($route), 81 | 'action' => $this->getRouteAction($route), 82 | 'middleware' => $this->getRouteMiddleware($route), 83 | 'map' => $this->getRouteMapTo($route) 84 | ]); 85 | } 86 | } 87 | 88 | /** 89 | * Apply filters on routes if user provide 90 | */ 91 | private function applyFilters() 92 | { 93 | $availableOptions = ['name', 'method', 'uri', 'action', 'middleware']; 94 | foreach ($this->options() as $key => $option) { 95 | if (in_array($key, $availableOptions) && null != $option) { 96 | foreach ($this->routes as $index => $route) { 97 | if (!str_contains(strtolower($route[$key]), strtolower($option))) 98 | unset($this->routes[$index]); 99 | } 100 | } 101 | } 102 | } 103 | 104 | /** 105 | * Get the route name 106 | * @param $route 107 | * @return null 108 | */ 109 | private function getRouteName($route) 110 | { 111 | return (isset($route['action']['as'])) ? $route['action']['as'] : ''; 112 | } 113 | 114 | /** 115 | * Get the route action type 116 | * @param $route 117 | * @return string 118 | */ 119 | private function getRouteAction($route) 120 | { 121 | return ($this->isClosureRoute($route)) ? 'Closure' : 'Controller'; 122 | } 123 | 124 | /** 125 | * Get where the route map to 126 | * @param $route 127 | * @return string 128 | */ 129 | private function getRouteMapTo($route) 130 | { 131 | return (!$this->isClosureRoute($route)) ? $route['action']['uses'] : ''; 132 | } 133 | 134 | /** 135 | * Get route middleware 136 | * @param $route 137 | * @return string 138 | */ 139 | private function getRouteMiddleware($route) 140 | { 141 | if (isset($route['action']['middleware'])) { 142 | return join(',', $route['action']['middleware']); 143 | } 144 | return ''; 145 | } 146 | 147 | /** 148 | * Check if the route is closure or controller route 149 | * @param $route 150 | * @return bool 151 | */ 152 | private function isClosureRoute($route) 153 | { 154 | return !isset($route['action']['uses']); 155 | } 156 | 157 | /** 158 | * Get console input options 159 | * @return array 160 | */ 161 | protected function getOptions() 162 | { 163 | return [ 164 | ['method', 'method', InputOption::VALUE_OPTIONAL, 'Method'], 165 | ['uri', 'uri', InputOption::VALUE_OPTIONAL, 'Uri'], 166 | ['name', 'name', InputOption::VALUE_OPTIONAL, 'Name'], 167 | ['action', 'action', InputOption::VALUE_OPTIONAL, 'Action'], 168 | ['middleware', 'middleware', InputOption::VALUE_OPTIONAL, 'Middleware'], 169 | ['map', 'map', InputOption::VALUE_OPTIONAL, 'Map to'], 170 | ['reverse', 'r', InputOption::VALUE_NONE, 'Reverse route list'] 171 | ]; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/LumenRouteListServiceProvider.php: -------------------------------------------------------------------------------- 1 | commands($this->commands); 33 | } 34 | } 35 | --------------------------------------------------------------------------------