diff --git a/CHANGELOG.md b/CHANGELOG.md index fba1b25..9f1c545 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # Changelog -## 0.1.21 - WIP +## 0.2.0 - WIP ### Add -- CI/CD: Add Caching vendors in GitHub actions pipeline +- You can watch your LaraLens report with your browser (not just with your terminal); +- Makefile to manage development tasks; +- Add timeout when checking HTTP connection; +- CI/CD: Add Caching vendors in GitHub actions pipeline. + ### Change -- DOCS: Update README, add some docs about skip database connection and database +- DOCS: Update README, add some docs about skip database connection and database. ## 0.1.20 - 2020-09-11 ### Fix 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 + + 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 diff --git a/config/config.php b/config/config.php index 48d0ee9..220311d 100755 --- a/config/config.php +++ b/config/config.php @@ -1,8 +1,10 @@ 'laralens', // URL prefix (default=laralens) + 'middleware' => ['web'], // middleware to use (default=web) + 'web-enabled' => 'off' // Activate web view (default=off) +]; diff --git a/resources/views/laralens/index.blade.php b/resources/views/laralens/index.blade.php new file mode 100644 index 0000000..78023ae --- /dev/null +++ b/resources/views/laralens/index.blade.php @@ -0,0 +1,98 @@ + + + + + + + + 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) + + + @elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) + + @elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) + + @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/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(); 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/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; 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()