Skip to content

Commit

Permalink
Merge pull request #1 from andrey-helldar/upgrade
Browse files Browse the repository at this point in the history
Upgrade to self-contained
  • Loading branch information
Andrey Helldar authored Oct 2, 2020
2 parents 5ccc9da + 11d1abb commit 7e77e2c
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 61 deletions.
Binary file added .github/home-page-images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
preset: psr12

risky: true

enabled:
- align_double_arrow
- align_equals
- align_phpdoc
- alpha_ordered_imports
- binary_operator_spaces
- blank_line_before_continue
- blank_line_before_declare
- blank_line_before_return
- blank_line_before_throw
- blank_line_before_try
- cast_spaces
- combine_consecutive_issets
- const_separation
- dir_constant
- fully_qualified_strict_types
- logical_operators
- method_separation
- no_alias_functions
- no_blank_lines_after_phpdoc
- no_blank_lines_between_traits
- no_empty_comment
- no_empty_phpdoc
- no_extra_block_blank_lines
- no_extra_consecutive_blank_lines
- no_short_bool_cast
- no_trailing_comma_in_singleline_array
- no_unneeded_control_parentheses
- no_unused_imports
- ordered_class_elements
- php_unit_construct
- php_unit_fqcn_annotation
- phpdoc_indent
- phpdoc_inline_tag
- phpdoc_link_to_see
- phpdoc_no_access
- phpdoc_no_empty_return
- phpdoc_no_package
- phpdoc_no_useless_inheritdoc
- phpdoc_order
- phpdoc_property
- phpdoc_return_self_reference
- phpdoc_scalar
- phpdoc_separation
- phpdoc_summary
- phpdoc_to_comment
- phpdoc_trim
- phpdoc_type_to_var
- phpdoc_types
- phpdoc_types_order
- phpdoc_var_without_name
- property_separation
- self_accessor
- short_array_syntax
- short_list_syntax
- single_line_class_definition
- single_line_throw
- single_quote
- space_after_semicolon
- standardize_not_equals
- ternary_to_null_coalescing
- trailing_comma_in_multiline_array
- trim_array_spaces
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
{
"name": "garygreen/pretty-routes",
"description": "Pretty routes for Laravel 5.",
"name": "andrey-helldar/pretty-routes",
"description": "Pretty routes for Laravel 6+",
"require": {
"laravel/framework": "5.*|6.*|7.*"
"php": "7.2",
"doctrine/annotations": "^1.0",
"laravel/framework": "^6.0|^7.0|^8.0"
},
"license": "MIT",
"authors": [
{
"name": "Gary Green",
"email": "[email protected]"
},
{
"name": "Andrey Helldar",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"PrettyRoutes\\": "src"
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"extra": {
"laravel": {
"providers": [
Expand Down
22 changes: 10 additions & 12 deletions config.php → config/pretty-routes.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
<?php

return [

/**
/*
* The endpoint to access the routes.
*/
'url' => 'routes',
'url' => 'routes',

/**
/*
* The middleware(s) to apply before attempting to access routes page.
*/
'middlewares' => [],
'middlewares' => [],

/**
/*
* Indicates whether to enable pretty routes only when debug is enabled (APP_DEBUG).
*/
'debug_only' => true,
'debug_only' => true,

/**
/*
* The methods to hide.
*/
'hide_methods' => [
'hide_methods' => [
'HEAD',
],

/**
/*
* The routes to hide with regular expression
*/
'hide_matching' => [
'#^_debugbar#',
'#^_ignition#',
'#^routes$#'
'#^routes$#',
],

];
10 changes: 6 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ Pretty Routes for Laravel

Visualise your routes in pretty format.

![Pretty Routes](https://raw.githubusercontent.com/garygreen/pretty-routes/master/screenshot.png)
<p align="center">
<img src="/.github/home-page-images/screenshot.png?raw=true" alt="Pretty Routes"/>
</p>

# Installation

```bash
composer require garygreen/pretty-routes
composer require andrey-helldar/pretty-routes
```

If your using autodiscovery in Laravel, it should just work.
Expand All @@ -19,12 +21,12 @@ Otherwise - add to your `config/app.php` providers array to where all your packa
PrettyRoutes\ServiceProvider::class,
```

By default the package exposes a `/routes` url. If you wish to configure this, publish the config.
By default, the package exposes a `/routes` url. If you wish to configure this, publish the config.

```bash
php artisan vendor:publish --provider="PrettyRoutes\ServiceProvider"
```

If accessing `/routes` isn't working, ensure that you've included the provider within the same area as all your package providers (before all your app's providers) to ensure it takes priority.

By default pretty routes only enables itself when `APP_DEBUG` env is true. You can configure this on the published config as above, or add any custom middlewares.
By default, pretty routes only enables itself when `APP_DEBUG` env is true. You can configure this on the published config as above, or add any custom middlewares.
6 changes: 5 additions & 1 deletion views/routes.blade.php → resources/views/routes.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
padding: 0.30em 0.8em;
}
.strike {
text-decoration: line-through;
}
table.hide-domains .domain {
display: none;
}
Expand Down Expand Up @@ -61,7 +65,7 @@
<td class="domain{{ strlen($route->domain()) == 0 ? ' domain-empty' : '' }}">{{ $route->domain() }}</td>
<td>{!! preg_replace('#({[^}]+})#', '<span class="text-warning">$1</span>', $route->uri()) !!}</td>
<td>{{ $route->getName() }}</td>
<td>{!! preg_replace('#(@.*)$#', '<span class="text-warning">$1</span>', $route->getActionName()) !!}</td>
<td class="{{ \PrettyRoutes\Facades\Annotation::isDeprecated($route->getActionName()) ? 'strike' : '' }}">{!! preg_replace('#(@.*)$#', '<span class="text-warning">$1</span>', $route->getActionName()) !!}</td>
<td>
@if (is_callable([$route, 'controllerMiddleware']))
{{ implode(', ', array_map($middlewareClosure, array_merge($route->middleware(), $route->controllerMiddleware()))) }}
Expand Down
7 changes: 7 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Illuminate\Support\Facades\Route;

Route::name('pretty-routes.show')
->middleware(config('pretty-routes.middlewares'))
->get(config('pretty-routes.url'), 'PrettyRoutes\PrettyRoutesController@show');
Binary file removed screenshot.png
Binary file not shown.
19 changes: 19 additions & 0 deletions src/Facades/Annotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PrettyRoutes\Facades;

use Illuminate\Support\Facades\Facade;
use PrettyRoutes\Support\Annotation as Support;

/**
* @method static boolean isDeprecated(string $controller, string $method = null)
* @method static boolean isDeprecatedClass(string $controller)
* @method static boolean isDeprecatedMethod(string $controller, string $method)
*/
class Annotation extends Facade
{
protected static function getFacadeAccessor()
{
return Support::class;
}
}
26 changes: 11 additions & 15 deletions src/PrettyRoutesController.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<?php namespace PrettyRoutes;
<?php

use Route;
use Closure;
namespace PrettyRoutes;

class PrettyRoutesController {
use Closure;
use Illuminate\Routing\Controller as BaseController;
use PrettyRoutes\Support\Routes;

class PrettyRoutesController extends BaseController
{
/**
* Show pretty routes.
*
* @param \PrettyRoutes\Support\Routes $routes
*
* @return \Illuminate\Http\Response
*/
public function show()
public function show(Routes $routes)
{
$middlewareClosure = function ($middleware) {
return $middleware instanceof Closure ? 'Closure' : $middleware;
};

$routes = collect(Route::getRoutes());

foreach (config('pretty-routes.hide_matching') as $regex) {
$routes = $routes->filter(function ($value, $key) use ($regex) {
return !preg_match($regex, $value->uri());
});
}

return view('pretty-routes::routes', [
'routes' => $routes,
'routes' => $routes->get(),
'middlewareClosure' => $middlewareClosure,
]);
}

}
46 changes: 21 additions & 25 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
<?php namespace PrettyRoutes;
<?php

use Route;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
namespace PrettyRoutes;

class ServiceProvider extends IlluminateServiceProvider {
use Illuminate\Support\ServiceProvider as BaseServiceProvider;

/**
* Register.
*
* @return
*/
class ServiceProvider extends BaseServiceProvider
{
public function register()
{
//
}
if ($this->isDisabled()) {
return;
}

/**
* Boot.
*
* @return void
*/
public function boot()
{
$this->mergeConfigFrom(
__DIR__ . '/../config.php', 'pretty-routes'
__DIR__ . '/../config/pretty-routes.php',
'pretty-routes'
);
}

if (config('pretty-routes.debug_only', true) && empty(config('app.debug'))) {
public function boot()
{
if ($this->isDisabled()) {
return;
}

$this->loadViewsFrom(realpath(__DIR__ . '/../views'), 'pretty-routes');
$this->loadViewsFrom(realpath(__DIR__ . '/../resources/views'), 'pretty-routes');

$this->publishes([
__DIR__ . '/../config.php' => config_path('pretty-routes.php')
__DIR__ . '/../config/pretty-routes.php' => config_path('pretty-routes.php'),
]);

Route::get(config('pretty-routes.url'), 'PrettyRoutes\PrettyRoutesController@show')
->name('pretty-routes.show')
->middleware(config('pretty-routes.middlewares'));
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
}

protected function isDisabled(): bool
{
return config('pretty-routes.debug_only', true) && empty(config('app.debug'));
}
}
Loading

0 comments on commit 7e77e2c

Please sign in to comment.