From 7c19ebfdbcff17a43d27b587f0b8732074ef1bcb Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sat, 19 Sep 2020 20:49:56 +0200 Subject: [PATCH 01/10] Create Makefile --- Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f1af603 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ + +help: ## Show this help. + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' + +phpstan: ## Execute phpstan + phpstan analyse src --level=1 + +test: ## Execute phpunit + vendor/bin/phpunit + +coverage: ## Execute the coverage test + vendor/bin/phpunit --coverage-text + +phpcs: ## execute phpcs + phpcs src + +allcheck: phpcs phpstan ## all check + + From 3645ba10b8502255f24dbc0ea021e473e7c21815 Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sat, 19 Sep 2020 20:51:44 +0200 Subject: [PATCH 02/10] create config - prefix: url prefix for accessing to page - middleware : middleware to use when accessing the controller (default web) - web-enabled : on. | off on. if you want to enable the page. if it is not "on" you will receive 401 as http status --- config/config.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/config.php b/config/config.php index 48d0ee9..0538427 100755 --- a/config/config.php +++ b/config/config.php @@ -4,5 +4,7 @@ * You can place your custom package configuration in here. */ return [ - -]; \ No newline at end of file + 'prefix' => 'laralens', + 'middleware' => ['web'], + 'web-enabled' => 'on' // 'on' to activate LaraLens Web view +]; From 884ae887f6fe328db90f6534c3d84d799c2d13a7 Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sat, 19 Sep 2020 20:52:05 +0200 Subject: [PATCH 03/10] fix typo --- src/Console/LaraLensCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/LaraLensCommand.php b/src/Console/LaraLensCommand.php index 2deef7c..9617855 100644 --- a/src/Console/LaraLensCommand.php +++ b/src/Console/LaraLensCommand.php @@ -149,7 +149,7 @@ private function overview($checkTable = "users", $columnSorting = "created_at", $ll = new LaraLens(); if ($show & self::OPTION_SHOW_CONFIGS) { $output = $ll->getConfigs(); - $this->printOutput(["Config key via config()", "Values"], $output->toArray()); + $this->printOutput(["Config keys via config()", "Values"], $output->toArray()); } if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { $output = $ll->getRuntimeConfigs(); From 85027cb129d585352375140e3256c2b5d72e26e9 Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sat, 19 Sep 2020 20:54:18 +0200 Subject: [PATCH 04/10] setting timeoout when is called http GET --- src/Lens/LaraHttp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lens/LaraHttp.php b/src/Lens/LaraHttp.php index 3a25779..434c376 100644 --- a/src/Lens/LaraHttp.php +++ b/src/Lens/LaraHttp.php @@ -13,7 +13,7 @@ public static function get($url) { $client = new Client(); try { - $response = new LaraHttpResponse($client->get($url)); + $response = new LaraHttpResponse($client->get($url, ['timeout' => 1])); } catch (GuzzleException $e) { $response = null; throw $e; From b774e0b3e448ddcc49085593f9e068f06ab445cf Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sat, 19 Sep 2020 20:58:16 +0200 Subject: [PATCH 05/10] now, Laralens is not just a terminal command but also a web page !!! --- resources/views/laralens/index.blade.php | 107 ++++++++++++++++++++ routes/web.php | 7 ++ src/Http/Controllers/Controller.php | 15 +++ src/Http/Controllers/LaraLensController.php | 60 +++++++++++ src/LaraLensServiceProvider.php | 23 ++++- src/Lens/Traits/FilesystemLens.php | 1 - 6 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 resources/views/laralens/index.blade.php create mode 100644 routes/web.php create mode 100644 src/Http/Controllers/Controller.php create mode 100644 src/Http/Controllers/LaraLensController.php diff --git a/resources/views/laralens/index.blade.php b/resources/views/laralens/index.blade.php new file mode 100644 index 0000000..d7dcb52 --- /dev/null +++ b/resources/views/laralens/index.blade.php @@ -0,0 +1,107 @@ + + + + + + + + + + + + + LaraLens + + + + + + +@foreach( $data as $item) +
+
+

+ {{$item['title']}} +

+

+ {{$item['description']}} +

+
+
+
+ @foreach( $item['data'] as $line) +
+
+ {{ $line['label'] }} +
+
+ {{ $line['value'] }} + +
+
+ @endforeach +
+
+
+@endforeach + +@foreach( $checks as $item) + @if(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_HINT) +
+

{{ $item['label'] }}

+

{{ $item['value'] }}

+
+ + @elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) +
+

{{ $item['label'] }}

+

{{ $item['value'] }}

+
+ @elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) +
+

{{ $item['label'] }}

+

{{ $item['value'] }}

+
+ @else + + + @endif + +@endforeach + + + diff --git a/routes/web.php b/routes/web.php new file mode 100644 index 0000000..17d4cc6 --- /dev/null +++ b/routes/web.php @@ -0,0 +1,7 @@ +name('laralens.index'); + diff --git a/src/Http/Controllers/Controller.php b/src/Http/Controllers/Controller.php new file mode 100644 index 0000000..1ee8574 --- /dev/null +++ b/src/Http/Controllers/Controller.php @@ -0,0 +1,15 @@ + 'off']); + } + $ll = new LaraLens(); + + + + $data = [ + [ + "title" => "Check Server requirements", + "description" => "Check Server requirements", + "data" => $ll->checkServerRequirements()->toArray() + ], + [ + "title" => "Configs", + "description" => "Config keys via config()", + "data" => $ll->getConfigs()->toArray() + ], + [ + "title" => "Runtime", + "description" => "Laravel Runtime configs", + "data" => $ll->getRuntimeConfigs()->toArray() + ], + [ + "title" => "Check files", + "description" => "Check files consistency / exists", + "data" => $ll->checkFiles()->toArray() + ], + [ + "title" => "Connections", + "description" => "Check connections", + "data" => $ll->getConnections('')->toArray() + ], + [ + "title" => "Database", + "description" => "Config Database", + "data" => $ll->getDatabase()->toArray() + ], + [ + "title" => "Credits", + "description" => "LaraLens app", + "data" => $ll->getCredits()->toArray() + ], + ]; + + $checks = $ll->checksBag->toArray(); + + return view('lara-lens::laralens.index', ['data' => $data, 'checks' => $checks]); + } +} diff --git a/src/LaraLensServiceProvider.php b/src/LaraLensServiceProvider.php index e80e0b3..6f3a627 100755 --- a/src/LaraLensServiceProvider.php +++ b/src/LaraLensServiceProvider.php @@ -5,6 +5,7 @@ use HiFolks\LaraLens\Console\LaraLensCommand; use Illuminate\Support\ServiceProvider; use HiFolks\LaraLens\Lens\LaraLens; +use Illuminate\Support\Facades\Route; class LaraLensServiceProvider extends ServiceProvider { @@ -17,9 +18,10 @@ public function boot() * Optional methods to load your package assets */ // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'lara-lens'); - // $this->loadViewsFrom(__DIR__.'/../resources/views', 'lara-lens'); + $this->loadViewsFrom(__DIR__ . '/../resources/views', 'lara-lens'); // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - // $this->loadRoutesFrom(__DIR__.'/routes.php'); + //$this->loadRoutesFrom(__DIR__.'/routes.php'); + $this->registerRoutes(); if ($this->app->runningInConsole()) { $this->publishes( @@ -53,6 +55,23 @@ public function boot() } } + + protected function registerRoutes() + { + Route::group($this->routeConfiguration(), function () { + $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); + }); + } + + protected function routeConfiguration() + { + + return [ + 'prefix' => config('lara-lens.prefix', 'laralens-diagnostic'), + 'middleware' => config('lara-lens.middleware'), + ]; + } + /** * Register the application services. */ diff --git a/src/Lens/Traits/FilesystemLens.php b/src/Lens/Traits/FilesystemLens.php index 3232c25..2cefb7b 100644 --- a/src/Lens/Traits/FilesystemLens.php +++ b/src/Lens/Traits/FilesystemLens.php @@ -5,7 +5,6 @@ use HiFolks\LaraLens\ResultLens; use Illuminate\Support\Facades\App; - trait FilesystemLens { public function checkFiles() From ae4bd0be6fbbc79e8d5bfc8121d487fde3ad96cc Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sun, 20 Sep 2020 16:28:38 +0200 Subject: [PATCH 06/10] adjusting. default config --- config/config.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.php b/config/config.php index 0538427..220311d 100755 --- a/config/config.php +++ b/config/config.php @@ -1,10 +1,10 @@ 'laralens', - 'middleware' => ['web'], - 'web-enabled' => 'on' // 'on' to activate LaraLens Web view + 'prefix' => 'laralens', // URL prefix (default=laralens) + 'middleware' => ['web'], // middleware to use (default=web) + 'web-enabled' => 'off' // Activate web view (default=off) ]; From b7b76af8e1da734cce6c6cb995eee58ee75e7c3b Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sun, 20 Sep 2020 16:58:07 +0200 Subject: [PATCH 07/10] Update README file for Web report --- README.md | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1aed11..b3caefc 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LaraLens -![CICD Github Actions](https://github.com/Hi-Folks/lara-lens/workflows/PHP%20Composer/badge.svg) +![CI/CD Github Actions](https://github.com/Hi-Folks/lara-lens/workflows/PHP%20Composer/badge.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/hi-folks/lara-lens) ![GitHub Release Date](https://img.shields.io/github/release-date/hi-folks/lara-lens) ![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/hi-folks/lara-lens) @@ -112,6 +112,39 @@ composer test Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. +## Usage as Web Page + +LaraLens provides information with the command line via terminal as shown above. +You have also the opportunity to see the information via your web browser. +You can enable web view via the configuration. + +Publish default configuration for LaraLens in your Laravel Application: +```shell script +php artisan vendor:publish --provider="HiFolks\LaraLens\LaraLensServiceProvider" --tag="config" +``` + +After that,you will have a new configuration file in your config directory. The file is: config/lara-lens.php + +With the following configuration you will enable the web view (_web-enabled_ parameter) under _/laralens/_ path: + +```php +return [ + 'prefix' => 'laralens', // URL prefix (default=laralens) + 'middleware' => ['web'], // middleware to use (default=web) + 'web-enabled' => 'on' // Activate web view (default=off) +]; +``` + +### Web view configuration hint +LaraLens shows some internal configuration of your Laravel application, so I suggest you to disable it in a production environment. +To disable LaraLens web view, make sure that _web-enabled_ is _off_: +``` +'web-enabled' => 'off' +``` + + + + ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. @@ -125,7 +158,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Credits - [Roberto Butti](https://github.com/hi-folks) -- [All Contributors](../../contributors) +- [All Contributors](https://github.com/Hi-Folks/lara-lens/graphs/contributors) - [Laravel Package Boilerplate](https://laravelpackageboilerplate.com) ## Who talks about LaraLens From e8f64007ccff5f9cbdb6acb1fd20e8e48491cd23 Mon Sep 17 00:00:00 2001 From: Roberto B Date: Sun, 20 Sep 2020 16:58:48 +0200 Subject: [PATCH 08/10] Avoid to load not existent icoons --- resources/views/laralens/index.blade.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/resources/views/laralens/index.blade.php b/resources/views/laralens/index.blade.php index d7dcb52..58542da 100644 --- a/resources/views/laralens/index.blade.php +++ b/resources/views/laralens/index.blade.php @@ -4,16 +4,7 @@ - - - - - LaraLens @@ -21,10 +12,10 @@