Skip to content

Commit

Permalink
Merge pull request #25 from Hi-Folks/feature/22-web
Browse files Browse the repository at this point in the history
Feature/22 web
  • Loading branch information
roberto-butti authored Sep 20, 2020
2 parents ccb4889 + 7280e90 commit 1ce6812
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 13 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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


37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/*
* You can place your custom package configuration in here.
* LaraLens Configuration.
*/
return [

];
'prefix' => 'laralens', // URL prefix (default=laralens)
'middleware' => ['web'], // middleware to use (default=web)
'web-enabled' => 'off' // Activate web view (default=off)
];
98 changes: 98 additions & 0 deletions resources/views/laralens/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<title>LaraLens</title>
</head>
<body>


<nav class="relative flex flex-wrap items-center justify-between px-2 py-3 navbar-expand-lg bg-yellow-500 mb-3">
<div class="container px-4 mx-auto flex flex-wrap items-center justify-between">
<div class="w-full relative flex justify-between lg:w-auto px-4 lg:static lg:block lg:justify-start font-bold leading-relaxed inline-block mr-4 py-2 whitespace-no-wrap text-white">

LaraLens

</div>
<div class="lg:flex flex-grow items-center" id="example-navbar-warning">
<ul class="flex flex-col lg:flex-row list-none ml-auto">
<li class="nav-item">
<a class="px-3 py-2 flex items-center text-xs uppercase font-bold leading-snug text-white hover:opacity-75" href="https://medium.com/@robertodev/laralens-a-laravel-command-for-inspecting-configuration-2bbb4e714cf7">
Tutorial
</a>
</li>
<li class="nav-item">
<a class="px-3 py-2 flex items-center text-xs uppercase font-bold leading-snug text-white hover:opacity-75" href="https://packagist.org/packages/hi-folks/lara-lens">
Packagist
</a>
</li>
<li class="nav-item">
<a class="px-3 py-2 flex items-center text-xs uppercase font-bold leading-snug text-white hover:opacity-75" href="https://github.com/Hi-Folks/lara-lens">
GitHub
</a>
</li>
</ul>
</div>
</div>
</nav>

@foreach( $data as $item)
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<div class="px-4 py-5 border-b border-gray-200 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">
{{$item['title']}}
</h3>
<p class="mt-1 max-w-2xl text-sm leading-5 text-gray-500">
{{$item['description']}}
</p>
</div>
<div>
<dl class="divide-y divide-gray-400">
@foreach( $item['data'] as $line)
<div class="{{ $loop->even ? "bg-gray-200" : "bg-white" }} px-4 py-1 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm leading-5 font-medium text-gray-700">
{{ $line['label'] }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ $line['value'] }}

</dd>
</div>
@endforeach
</dl>
</div>
</div>
@endforeach

@foreach( $checks as $item)
@if(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_HINT)
<div class="bg-blue-100 border-l-4 border-blue-500 text-blue-700 p-4" role="alert">
<p class="font-bold">{{ $item['label'] }}</p>
<p>{{ $item['value'] }}</p>
</div>

@elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR)
<div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4" role="alert">
<p class="font-bold">{{ $item['label'] }}</p>
<p>{{ $item['value'] }}</p>
</div>
@elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING)
<div class="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4" role="alert">
<p class="font-bold">{{ $item['label'] }}</p>
<p>{{ $item['value'] }}</p>
</div>
@else
<div class="bg-grey-100 border-l-4 border-grey-500 text-grey-700 p-4" role="alert">
<p class="font-bold">{{ $item['label'] }}</p>
<p>{{ $item['value'] }}</p>
</div>

@endif

@endforeach

</body>
</html>
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;
use HiFolks\LaraLens\Http\Controllers\LaraLensController;

Route::get('/', [LaraLensController::class, 'index'])->name('laralens.index');

2 changes: 1 addition & 1 deletion src/Console/LaraLensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace HiFolks\LaraLens\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
use AuthorizesRequests;
use DispatchesJobs;
use ValidatesRequests;
}
60 changes: 60 additions & 0 deletions src/Http/Controllers/LaraLensController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace HiFolks\LaraLens\Http\Controllers;

use HiFolks\LaraLens\Lens\LaraLens;

class LaraLensController extends Controller
{
public function index()
{
if (config('lara-lens.web-enabled') != 'on') {
abort(403, 'Unauthorized action.', ['X-Laralens' => '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]);
}
}
23 changes: 21 additions & 2 deletions src/LaraLensServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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(
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Lens/LaraHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Lens/Traits/FilesystemLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use HiFolks\LaraLens\ResultLens;
use Illuminate\Support\Facades\App;


trait FilesystemLens
{
public function checkFiles()
Expand Down

0 comments on commit 1ce6812

Please sign in to comment.