├── pint.json ├── LaraLens-Laravel-Artisan.png ├── routes └── web.php ├── phpstan.neon ├── phpcs.xml ├── src ├── LaraLensFacade.php ├── Http │ └── Controllers │ │ ├── Controller.php │ │ └── LaraLensController.php ├── Lens │ ├── Traits │ │ ├── BaseTraits.php │ │ ├── TermOutput.php │ │ ├── OperatingSystemLens.php │ │ ├── HttpConnectionLens.php │ │ ├── FilesystemLens.php │ │ ├── ConfigLens.php │ │ ├── DatabaseLens.php │ │ └── RuntimeLens.php │ ├── LaraHttp.php │ ├── Objects │ │ └── LaraHttpResponse.php │ └── LaraLens.php ├── ResultLens.php ├── LaraLensServiceProvider.php └── Console │ └── LaraLensCommand.php ├── config └── config.php ├── psalm.xml ├── rector.php ├── .github └── workflows │ ├── php-lint.yml │ └── php-code-quality.yml ├── phpunit.xml.dist.bak ├── LICENSE.md ├── resources └── views │ └── laralens │ ├── term │ ├── table.blade.php │ └── checks.blade.php │ └── index.blade.php ├── composer.json ├── CONTRIBUTING.md ├── README.md └── CHANGELOG.md /pint.json: -------------------------------------------------------------------------------- 1 | { 2 | "preset": "psr12" 3 | } 4 | -------------------------------------------------------------------------------- /LaraLens-Laravel-Artisan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hi-Folks/lara-lens/HEAD/LaraLens-Laravel-Artisan.png -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('laralens.index'); 7 | -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | includes: 2 | - ./vendor/larastan/larastan/extension.neon 3 | parameters: 4 | reportUnmatchedIgnoredErrors: false 5 | ignoreErrors: 6 | - '#Parameter .1 \$separator of function explode expects non-empty-string, string given.#' 7 | 8 | level: 5 9 | paths: 10 | - src 11 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHPCS configuration file. 4 | src 5 | */exclude/* 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/LaraLensFacade.php: -------------------------------------------------------------------------------- 1 | env('LARALENS_PREFIX', 'laralens'), // URL prefix (default=laralens) 8 | 'middleware' => explode(';', env('LARALENS_MIDDLEWARE', 'web')), // middleware (default=web) more separate with ; 9 | 'web-enabled' => env('LARALENS_WEB_ENABLED', 'off') // Activate web view (default=off) 10 | ]; 11 | -------------------------------------------------------------------------------- /src/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | 3) { 14 | if (Str::startsWith($value, $curDir)) { 15 | $value = "." . Str::after($value, $curDir); 16 | } 17 | } 18 | return $value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /psalm.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /rector.php: -------------------------------------------------------------------------------- 1 | paths([ 11 | __DIR__ . '/src' 12 | ]); 13 | 14 | // register a single rule 15 | // $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); 16 | 17 | // define sets of rules 18 | $rectorConfig->sets([ 19 | LevelSetList::UP_TO_PHP_80 20 | ]); 21 | }; 22 | -------------------------------------------------------------------------------- /src/Lens/LaraHttp.php: -------------------------------------------------------------------------------- 1 | get($url, ['timeout' => 1])); 16 | } catch (GuzzleException $e) { 17 | $response = null; 18 | throw $e; 19 | } 20 | return $response; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/php-lint.yml: -------------------------------------------------------------------------------- 1 | name: PHP Syntax Checker (Lint) 2 | 3 | on: 4 | push: 5 | branches: [ develop ] 6 | pull_request: 7 | branches: [ develop ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | 18 | - name: Validate composer.json and composer.lock 19 | run: composer validate 20 | 21 | - name: Install dependencies 22 | run: composer install --prefer-dist --no-progress 23 | 24 | - name: Run test suite 25 | run: composer run-script test 26 | 27 | - name: PHP Syntax Checker (Lint) 28 | uses: StephaneBour/actions-php-lint@8.3 29 | with: 30 | dir: './src' 31 | -------------------------------------------------------------------------------- /src/Lens/Objects/LaraHttpResponse.php: -------------------------------------------------------------------------------- 1 | response->getStatusCode(); 24 | } 25 | 26 | /** 27 | * Return true if the status code of the HTTP response is an error 28 | * 29 | * @return bool 30 | */ 31 | public function failed() 32 | { 33 | return ($this->response->getStatusCode() >= 400); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Lens/Traits/TermOutput.php: -------------------------------------------------------------------------------- 1 | $title, 16 | 'rows' => $rows 17 | ]) 18 | ); 19 | } 20 | 21 | public function printChecksTerm(array $rows): void 22 | { 23 | render( 24 | view('lara-lens::laralens.term.checks', [ 25 | 'rows' => $rows 26 | ]) 27 | ); 28 | } 29 | public function title(string $title): void 30 | { 31 | render("
$title
"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /phpunit.xml.dist.bak: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | src/ 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tests 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Roberto Butti 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/Lens/Traits/OperatingSystemLens.php: -------------------------------------------------------------------------------- 1 | "Operating System", 13 | "n" => "Hostname", 14 | "r" => "Release name", 15 | "v" => "Version info", 16 | "m" => "Machine Name", 17 | "a" => "Full infos" 18 | ]; 19 | 20 | foreach ($modes as $key => $title) { 21 | $results->add( 22 | $title, 23 | php_uname($key) 24 | ); 25 | } 26 | } 27 | 28 | public function getOsConfigs(): \HiFolks\LaraLens\ResultLens 29 | { 30 | $results = new ResultLens(); 31 | $results->add( 32 | "PHP script owner's UID", 33 | getmyuid() 34 | ); 35 | $results->add( 36 | "Current User", 37 | get_current_user() 38 | ); 39 | $this->getUnameValues($results); 40 | return $results; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Lens/LaraLens.php: -------------------------------------------------------------------------------- 1 | checksBag = new ResultLens(); 30 | } 31 | 32 | /** 33 | * @return ResultLens 34 | */ 35 | public function getCredits() 36 | { 37 | $results = new ResultLens(); 38 | $results->add( 39 | "App", 40 | "powered by LaraLens" 41 | ); 42 | 43 | 44 | return $results; 45 | } 46 | 47 | 48 | /** 49 | * @return string 50 | */ 51 | public static function printBool(bool $b) 52 | { 53 | return $b ? "Yes" : "No"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Lens/Traits/HttpConnectionLens.php: -------------------------------------------------------------------------------- 1 | add( 15 | "app.url configuration", 16 | $app_url 17 | ); 18 | $url = url($checkPath); 19 | $results->add( 20 | "url()->full()", 21 | url()->full() 22 | ); 23 | $results->add( 24 | "Connection HTTP URL", 25 | $url 26 | ); 27 | try { 28 | $response = LaraHttp::get($url); 29 | $results->add( 30 | "Connection HTTP Status", 31 | $response->status() 32 | ); 33 | if ($response->failed()) { 34 | $checkUrlHint = "Check APP_URL '" . $app_url . "' in .env file "; 35 | if ($checkPath !== "") { 36 | $checkUrlHint .= " or check this path: '" . $checkPath . "' in routing file (routes/web.php)"; 37 | } 38 | $this->checksBag->addWarningAndHint( 39 | "Connection HTTP Status", 40 | "Connection response not 20x, status code: " . $response->status() . " for " . $url, 41 | $checkUrlHint 42 | ); 43 | } 44 | } catch (\Exception $e) { 45 | $results->add( 46 | "Connection HTTP Status", 47 | "Error connection" 48 | ); 49 | $this->checksBag->addErrorAndHint( 50 | "Connection HTTP Status", 51 | "Connection Error: " . $e->getMessage(), 52 | "Check this URL: " . $app_url . " in .env file APP_URL" 53 | ); 54 | } 55 | return $results; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /resources/views/laralens/term/table.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{ $title }} 4 | 5 |
6 |
7 | 8 | @foreach ($rows as $row) 9 | @php 10 | $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); 11 | $label = Arr::get($row, "label", ""); 12 | @endphp 13 | @if ($label === "*** HINT") 14 |
15 | Hint: 16 | 17 |
18 | 19 | {{ Arr::get($row, "value", "") }} 20 | 21 |
22 |
23 | @else 24 |
25 | 26 | {{ Arr::get($row, "label", "")}} 27 | 28 | 29 | 30 | 31 | 32 | @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) 33 | 34 | {{ Arr::get($row, "value", "")}} 35 | 36 | @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) 37 | 38 | {{ Arr::get($row, "value", "")}} 39 | 40 | @else 41 | 42 | {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} 43 | 44 | @endif 45 | 46 |
47 | @endif 48 | @endforeach 49 |
50 |
51 | 52 |
53 | -------------------------------------------------------------------------------- /.github/workflows/php-code-quality.yml: -------------------------------------------------------------------------------- 1 | name: Code Quality Workflow 2 | on: 3 | push: 4 | branches: 5 | - develop 6 | - features/** 7 | - feature/** 8 | - upgrade/** 9 | pull_request: 10 | branches: [ develop ] 11 | 12 | jobs: 13 | laravel-tests: 14 | strategy: 15 | matrix: 16 | operating-system: [ubuntu-latest] 17 | php-versions: [ '8.4', '8.3', '8.2', '8.1' ] 18 | dependency-stability: [ 'prefer-stable','prefer-lowest' ] 19 | 20 | runs-on: ${{ matrix.operating-system }} 21 | 22 | 23 | name: Test P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} 24 | 25 | steps: 26 | - uses: actions/checkout@v4 27 | - name: Install PHP versions 28 | uses: shivammathur/setup-php@v2 29 | with: 30 | php-version: ${{ matrix.php-versions }} 31 | - name: Install Dependencies 32 | run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist 33 | 34 | - name: Update Dependencies with latest stable 35 | if: matrix.dependency-stability == 'prefer-stable' 36 | run: composer update --prefer-stable 37 | - name: Update Dependencies with lowest stable 38 | if: matrix.dependency-stability == 'prefer-lowest' 39 | run: composer update --prefer-stable --prefer-lowest 40 | 41 | # Code quality 42 | - name: Execute tests (Unit and Feature tests) via PHPUnit 43 | env: 44 | SESSION_DRIVER: array 45 | run: composer test 46 | 47 | 48 | laravel-check: 49 | strategy: 50 | matrix: 51 | operating-system: [ubuntu-latest] 52 | php-versions: [ '8.3' ] 53 | 54 | runs-on: ${{ matrix.operating-system }} 55 | 56 | 57 | name: Check P${{ matrix.php-versions }} - ${{ matrix.operating-system}} 58 | 59 | steps: 60 | - uses: actions/checkout@v4 61 | - name: Install PHP versions 62 | uses: shivammathur/setup-php@v2 63 | with: 64 | php-version: ${{ matrix.php-versions }} 65 | - name: Install Dependencies 66 | run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist 67 | 68 | - name: Execute Code Sniffer via phpcs 69 | run: | 70 | composer style-fix 71 | 72 | - name: Execute Code Static Analysis (PHP Stan + Larastan) 73 | run: | 74 | composer phpstan 75 | -------------------------------------------------------------------------------- /resources/views/laralens/term/checks.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if (sizeof($rows) > 0) 3 |
4 | CHECK: issues found 5 | 6 |
7 | @else 8 |
9 | CHECK: everything looks good 10 | 11 |
12 | @endif 13 |
14 | @foreach ($rows as $row) 15 | @php 16 | $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); 17 | $label = Arr::get($row, "label", ""); 18 | @endphp 19 | @if ($label === "*** HINT") 20 |
21 | 💡 Hint: 22 | 23 | 24 | {{ Arr::get($row, "value", "") }} 25 | 26 | 27 |
28 | @else 29 |
$lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR, 32 | 'bg-yellow text-black' => $lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING, 33 | 'bg-green text-white' => $lineType !== HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR 34 | && $lineType !== HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING, 35 | ])> 36 | {{ Arr::get($row, "label", "")}} 37 |
38 |
39 | @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) 40 | {{ Arr::get($row, "value", "")}} 41 | @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) 42 | {{ Arr::get($row, "value", "")}} 43 | @else 44 | {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} 45 | @endif 46 |
47 | @endif 48 | @endforeach 49 |
50 |
51 | -------------------------------------------------------------------------------- /src/Http/Controllers/LaraLensController.php: -------------------------------------------------------------------------------- 1 | 'off']); 13 | } 14 | $ll = new LaraLens(); 15 | 16 | 17 | 18 | $data = [ 19 | [ 20 | "title" => "Check Server requirements", 21 | "description" => "Check Server requirements", 22 | "data" => $ll->checkServerRequirements()->toArray() 23 | ], 24 | [ 25 | "title" => "Configs", 26 | "description" => "Config keys via config()", 27 | "data" => $ll->getConfigs()->toArray() 28 | ], 29 | [ 30 | "title" => "Runtime", 31 | "description" => "Laravel Runtime configs", 32 | "data" => $ll->getRuntimeConfigs()->toArray() 33 | ], 34 | [ 35 | "title" => "Check files", 36 | "description" => "Check files consistency / exists", 37 | "data" => $ll->checkFiles()->toArray() 38 | ], 39 | [ 40 | "title" => "Connections", 41 | "description" => "Check connections", 42 | "data" => $ll->getConnections('')->toArray() 43 | ], 44 | [ 45 | "title" => "Database", 46 | "description" => "Config Database", 47 | "data" => $ll->getDatabase()->toArray() 48 | ], 49 | [ 50 | "title" => "PHP Extensions", 51 | "description" => "List of PHP extensions loaded", 52 | "data" => $ll->getPhpExtensions()->toArray() 53 | ], 54 | [ 55 | "title" => "PHP INI", 56 | "description" => "List of php ini values", 57 | "data" => $ll->getPhpIniValues()->toArray() 58 | ], 59 | [ 60 | "title" => "Credits", 61 | "description" => "LaraLens app", 62 | "data" => $ll->getCredits()->toArray() 63 | ], 64 | ]; 65 | 66 | $checks = $ll->checksBag->toArray(); 67 | 68 | return view('lara-lens::laralens.index', ['data' => $data, 'checks' => $checks]); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/ResultLens.php: -------------------------------------------------------------------------------- 1 | reset(); 20 | } 21 | 22 | public function reset(): void 23 | { 24 | $this->result = collect(); 25 | $this->idx = -1; 26 | } 27 | 28 | public function addError($label, $value): void 29 | { 30 | $this->add($label, $value, true, self::LINE_TYPE_ERROR); 31 | } 32 | 33 | public function addWarning($label, $value): void 34 | { 35 | $this->add($label, $value, true, self::LINE_TYPE_WARNING); 36 | } 37 | public function addInfo($label, $value): void 38 | { 39 | $this->add($label, $value, true, self::LINE_TYPE_INFO); 40 | } 41 | 42 | 43 | public function addHint($value): void 44 | { 45 | $this->add("*** HINT", $value, true, self::LINE_TYPE_HINT); 46 | } 47 | public function addErrorAndHint($label, $errorMessage, $hintMessage): void 48 | { 49 | $this->addError($label, $errorMessage); 50 | $this->addHint($hintMessage); 51 | } 52 | public function addWarningAndHint($label, $warningMessage, $hintMessage): void 53 | { 54 | $this->addWarning($label, $warningMessage); 55 | $this->addHint($hintMessage); 56 | } 57 | public function addInfoAndHint($label, $infoMessage, $hintMessage): void 58 | { 59 | $this->addInfo($label, $infoMessage); 60 | $this->addHint($hintMessage); 61 | } 62 | 63 | public function add($label, $value, $forceLine = false, $lineType = self::LINE_TYPE_DEFAULT): void 64 | { 65 | $this->result->push( 66 | [ 67 | "label" => $label, 68 | "value" => $value, 69 | "isLine" => $forceLine, 70 | "lineType" => $lineType 71 | ] 72 | ); 73 | $this->idx++; 74 | } 75 | 76 | /** 77 | * @return bool 78 | */ 79 | public static function isMessageLine(string $lineType) 80 | { 81 | return (($lineType === self::LINE_TYPE_ERROR) || 82 | ($lineType === self::LINE_TYPE_WARNING) || 83 | ($lineType === self::LINE_TYPE_INFO)); 84 | } 85 | public static function isHintLine($lineType): bool 86 | { 87 | return ($lineType === self::LINE_TYPE_HINT); 88 | } 89 | 90 | 91 | public function toArray() 92 | { 93 | return $this->result->toArray(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hi-folks/lara-lens", 3 | "description": "Laravel Diagnostic command for configuration, db connection, http request", 4 | "keywords": [ 5 | "laravel", 6 | "diagnostic", 7 | "cli", 8 | "package", 9 | "command-line", 10 | "console", 11 | "hi-folks", 12 | "lara-lens" 13 | ], 14 | "homepage": "https://github.com/hi-folks/lara-lens", 15 | "license": "MIT", 16 | "type": "library", 17 | "authors": [ 18 | { 19 | "name": "Roberto Butti", 20 | "role": "Developer" 21 | } 22 | ], 23 | "require": { 24 | "php": "^8.0|^8.1|^8.2|^8.3|^8.4", 25 | "ext-json": "*", 26 | "guzzlehttp/guzzle": "^7.8", 27 | "nunomaduro/termwind": "^1.15|^2.0" 28 | }, 29 | "require-dev": { 30 | "doctrine/dbal": "^3.0|^4.0", 31 | "larastan/larastan": "^2.0", 32 | "laravel/pint": "^1.4", 33 | "orchestra/testbench": "^7.0|^8.0|^9.0", 34 | "pestphp/pest": "^2.34", 35 | "pestphp/pest-plugin-laravel": "^1.2|^2.3", 36 | "phpunit/phpunit": "^10.5", 37 | "rector/rector": "^0.14|^1.0" 38 | }, 39 | "autoload": { 40 | "psr-4": { 41 | "HiFolks\\LaraLens\\": "src" 42 | } 43 | }, 44 | "autoload-dev": { 45 | "psr-4": { 46 | "HiFolks\\LaraLens\\Tests\\": "tests" 47 | } 48 | }, 49 | "scripts": { 50 | "all": [ 51 | "@style-fix", 52 | "@phpstan", 53 | "@test" 54 | ], 55 | "style-fix": "pint", 56 | "style-check": "pint --test", 57 | "phpstan": "phpstan analyse -c ./phpstan.neon --no-progress", 58 | "test": "./vendor/bin/pest --order-by random", 59 | "rector": "rector process --dry-run" 60 | }, 61 | "scripts-descriptions": { 62 | "test": "Run all tests, via PespPHP", 63 | "style-fix": "Fix the code style with PSR12", 64 | "style-check": "Check the code style with PSR12", 65 | "phpstan": "Run static code analysis via PHPStan", 66 | "rector": "Suggest refactoring to be more PHP 8 compliant", 67 | "all": "Execute tasks for fixing code style, static code analysis and tests" 68 | }, 69 | "config": { 70 | "sort-packages": true, 71 | "allow-plugins": { 72 | "composer/package-versions-deprecated": false, 73 | "pestphp/pest-plugin": true 74 | } 75 | }, 76 | "extra": { 77 | "laravel": { 78 | "providers": [ 79 | "HiFolks\\LaraLens\\LaraLensServiceProvider" 80 | ], 81 | "aliases": { 82 | "LaraLens": "HiFolks\\LaraLens\\LaraLensFacade" 83 | } 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Lens/Traits/FilesystemLens.php: -------------------------------------------------------------------------------- 1 | storage_path('app/public')]; 16 | //return $this->laravel['config']['filesystems.links'] ?? 17 | } 18 | public function checkFiles(): \HiFolks\LaraLens\ResultLens 19 | { 20 | $results = new ResultLens(); 21 | $envExists = file_exists(App::environmentFilePath()); 22 | if ($envExists) { 23 | $results->add( 24 | "Check .env exists", 25 | self::printBool($envExists) 26 | ); 27 | } else { 28 | $results->addWarningAndHint( 29 | "Check .env exists", 30 | ".env not exists", 31 | "Create .env file" 32 | ); 33 | } 34 | $results->add( 35 | "Check Languages directory", 36 | self::printBool(is_dir(App::langPath())) 37 | ); 38 | try { 39 | $langArray = scandir(App::langPath()); 40 | } catch (\Exception) { 41 | $langArray = false; 42 | } 43 | $languages = ""; 44 | if ($langArray) { 45 | $languages = implode(",", array_diff($langArray, ['..', '.', 'vendor'])); 46 | } else { 47 | $languages = "No language found"; 48 | $this->checksBag->addWarningAndHint( 49 | "List Languages directory", 50 | "No languages found in " . App::langPath(), 51 | "If your app needs translations, please fill " . App::langPath() . " or run `php artisan lang:publish`" 52 | ); 53 | } 54 | $results->add( 55 | "List Languages directory", 56 | $languages 57 | ); 58 | 59 | foreach ($this->links() as $link => $dir) { 60 | if (!file_exists($link)) { 61 | $this->checksBag->addWarningAndHint( 62 | "Check storage link", 63 | $this->stripPrefixDir($link) . " it doesn't exist.", 64 | "Check config/filesystem.php 'links' parameter, and execute 'php artisan storage:link'" 65 | ); 66 | } 67 | if (!file_exists($dir)) { 68 | $this->checksBag->addWarningAndHint( 69 | "Check storage target link", 70 | $this->stripPrefixDir($dir) . " it doesn't exist.", 71 | "Create directory target (for storage link) : " . $dir 72 | ); 73 | } 74 | 75 | $results->add( 76 | "Storage links:", 77 | "" 78 | ); 79 | $results->add( 80 | $this->stripPrefixDir($link), 81 | $this->stripPrefixDir($dir) 82 | ); 83 | } 84 | 85 | return $results; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/LaraLensServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadTranslationsFrom(__DIR__.'/../resources/lang', 'lara-lens'); 21 | $this->loadViewsFrom(__DIR__ . '/../resources/views', 'lara-lens'); 22 | // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); 23 | //$this->loadRoutesFrom(__DIR__.'/routes.php'); 24 | $this->registerRoutes(); 25 | 26 | if ($this->app->runningInConsole()) { 27 | $this->publishes( 28 | [ 29 | __DIR__ . '/../config/config.php' => config_path('lara-lens.php'), 30 | ], 31 | 'config' 32 | ); 33 | 34 | // Publishing the views. 35 | /*$this->publishes([ 36 | __DIR__.'/../resources/views' => resource_path('views/vendor/lara-lens'), 37 | ], 'views');*/ 38 | 39 | // Publishing assets. 40 | /*$this->publishes([ 41 | __DIR__.'/../resources/assets' => public_path('vendor/lara-lens'), 42 | ], 'assets');*/ 43 | 44 | // Publishing the translation files. 45 | /*$this->publishes([ 46 | __DIR__.'/../resources/lang' => resource_path('lang/vendor/lara-lens'), 47 | ], 'lang');*/ 48 | 49 | // Registering package commands. 50 | $this->commands( 51 | [ 52 | LaraLensCommand::class, 53 | ] 54 | ); 55 | } 56 | } 57 | 58 | 59 | protected function registerRoutes(): void 60 | { 61 | Route::group($this->routeConfiguration(), function () { 62 | $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); 63 | }); 64 | } 65 | 66 | /** 67 | * @return (\Illuminate\Config\Repository|mixed)[] 68 | * 69 | * @psalm-return array{prefix: \Illuminate\Config\Repository|mixed, middleware: \Illuminate\Config\Repository|mixed} 70 | */ 71 | protected function routeConfiguration(): array 72 | { 73 | return [ 74 | 'prefix' => config('lara-lens.prefix', 'laralens-diagnostic'), 75 | 'middleware' => config('lara-lens.middleware'), 76 | ]; 77 | } 78 | 79 | /** 80 | * Register the application services. 81 | */ 82 | public function register() 83 | { 84 | // Automatically apply the package configuration 85 | $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'lara-lens'); 86 | 87 | // Register the main class to use with the facade 88 | $this->app->singleton( 89 | 'lara-lens', 90 | fn () => new LaraLens() 91 | ); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Lens/Traits/ConfigLens.php: -------------------------------------------------------------------------------- 1 | $value) { 22 | $results->add( 23 | ".env " . $value, 24 | env($value) 25 | ); 26 | } 27 | return $results; 28 | } 29 | 30 | public function checkDebugEnv(ResultLens|null $results = null): \HiFolks\LaraLens\ResultLens 31 | { 32 | if (is_null($results)) { 33 | $results = new ResultLens(); 34 | } 35 | $debug = config("app.debug"); 36 | $env = config("app.env"); 37 | $results->add( 38 | "ENV", 39 | $env 40 | ); 41 | $results->add( 42 | "DEBUG", 43 | $debug 44 | ); 45 | if ($debug && $env === "production") { 46 | $this->checksBag->addWarningAndHint( 47 | "Check config ENV and DEBUG", 48 | "You have DEBUG mode in Production.", 49 | "Change you APP_DEBUG env parameter to false for Production environments" 50 | ); 51 | } 52 | return $results; 53 | } 54 | 55 | public function getConfigsDatabase(ResultLens|null $results = null): \HiFolks\LaraLens\ResultLens 56 | { 57 | if (is_null($results)) { 58 | $results = new ResultLens(); 59 | } 60 | $configKeys = [ 61 | "database.default", 62 | "database.connections." . config("database.default") . ".driver", 63 | "database.connections." . config("database.default") . ".url", 64 | "database.connections." . config("database.default") . ".host", 65 | "database.connections." . config("database.default") . ".port", 66 | "database.connections." . config("database.default") . ".username", 67 | "database.connections." . config("database.default") . ".database" 68 | ]; 69 | foreach ($configKeys as $key => $value) { 70 | $results->add( 71 | "" . $value, 72 | config($value) 73 | ); 74 | } 75 | return $results; 76 | } 77 | 78 | public function getConfigs() 79 | { 80 | $results = new ResultLens(); 81 | $results->add( 82 | "Running diagnostic", 83 | date('Y-m-d H:i:s') 84 | ); 85 | $configKeys = [ 86 | "app.timezone", 87 | "app.locale", 88 | "app.name", 89 | "app.url", 90 | ]; 91 | foreach ($configKeys as $key => $value) { 92 | $results->add( 93 | "" . $value, 94 | config($value) 95 | ); 96 | } 97 | $results = $this->checkDebugEnv($results); 98 | $results = $this->getConfigsDatabase($results); 99 | return $results; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Open a Pull Request 40 | 41 | In order to maintain consistency in the source code we are following PSR12 coding standard, and using PHP stan for static code analysis. 42 | You can use the command: 43 | ``` 44 | make allcheck 45 | ``` 46 | to launch 47 | - **[PSR-12 Coding Standard](https://www.php-fig.org/psr/psr-12/)**, under the hood is used [PintPHP](https://laravel.com/docs/9.x/pint); 48 | - **PHPstan** with [level 5](https://phpstan.org/user-guide/rule-levels) 49 | - **PestPHP** to execute all tests from ./tests/* 50 | 51 | I suggest to launch *composer all* before to commit or before to create PR. 52 | 53 | If you want to work on a PR, I suggest you to creating a new branch starting from **develop branch**, and use it also when you will submit your new **P**ull **R**equest on the original repository. 54 | 55 | If you want to contribute with an high quality PR, I suggest you to focus not just on the source code but also: 56 | 57 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 58 | 59 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 60 | 61 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 62 | 63 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 64 | 65 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 66 | 67 | **Happy coding**! 68 | -------------------------------------------------------------------------------- /resources/views/laralens/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | LaraLens 9 | 10 | 11 | 12 | 13 | 41 | 42 | @foreach( $data as $item) 43 |
44 |
45 |

46 | {{$item['title']}} 47 |

48 |

49 | {{$item['description']}} 50 |

51 |
52 |
53 |
54 | @foreach( $item['data'] as $line) 55 |
56 |
57 | {{ $line['label'] }} 58 |
59 |
60 | {{ $line['value'] }} 61 | 62 |
63 |
64 | @endforeach 65 |
66 |
67 |
68 | @endforeach 69 | 70 | @foreach( $checks as $item) 71 | @if(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_HINT) 72 | 76 | 77 | @elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) 78 | 82 | @elseif(\Illuminate\Support\Arr::get($item, "lineType", \HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT) === \HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) 83 | 87 | @else 88 | 92 | 93 | @endif 94 | 95 | @endforeach 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/Lens/Traits/DatabaseLens.php: -------------------------------------------------------------------------------- 1 | $value) { 19 | $stringTables = $stringTables . $value . ";"; 20 | } 21 | } 22 | return $stringTables; 23 | } 24 | 25 | public function getTablesListSqlite(): string 26 | { 27 | $tables = DB::table('sqlite_master') 28 | ->select('name') 29 | ->where('type', 'table') 30 | ->orderBy('name') 31 | ->pluck('name')->toArray(); 32 | $stringTables = implode(",", $tables); 33 | return $stringTables; 34 | } 35 | 36 | /** 37 | * Try to establish a db connection. 38 | * If it fails, return FALSE and fill checksBag. 39 | */ 40 | public function dbConnection(): false|\Illuminate\Database\Connection 41 | { 42 | $dbconnection = false; 43 | try { 44 | $dbconnection = DB::connection(); 45 | } catch (\Exception $e) { 46 | $dbconnection = false; 47 | $this->checksBag->addErrorAndHint( 48 | "Error Database connection", 49 | "- " . $e->getCode() . " - " . $e->getMessage(), 50 | "Check out your .env file for these parameters: DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD" 51 | ); 52 | } 53 | return $dbconnection; 54 | } 55 | 56 | public function getDatabaseConnectionInfos( 57 | Connection $dbConnection, 58 | ResultLens $results, 59 | $checkTable, 60 | $columnSorting 61 | ) { 62 | $connectionName = $dbConnection->getName(); 63 | $results->add( 64 | "Connection name", 65 | $connectionName 66 | ); 67 | $grammar = $dbConnection->getQueryGrammar(); 68 | $results->add( 69 | "Query Grammar", 70 | Str::afterLast($grammar::class, '\\') 71 | ); 72 | $driverName = $dbConnection->getDriverName(); 73 | $results->add( 74 | "Driver name", 75 | $driverName 76 | ); 77 | $databaseName = $dbConnection->getDatabaseName(); 78 | $results->add( 79 | "Database name", 80 | $databaseName 81 | ); 82 | $tablePrefix = $dbConnection->getTablePrefix(); 83 | $results->add( 84 | "Table prefix", 85 | $tablePrefix 86 | ); 87 | 88 | $pdo = null; 89 | $pdoIsOk = false; 90 | try { 91 | $pdo = $dbConnection->getPDO(); 92 | $pdoIsOk = true; 93 | } catch (\PDOException $e) { 94 | $this->checksBag->addWarningAndHint( 95 | "Access to PDO (database)", 96 | $e->getMessage(), 97 | "Check .env DB_*" 98 | ); 99 | } 100 | 101 | if (!$pdoIsOk) { 102 | if ($driverName === "mongodb") { 103 | $this->checksBag->addInfoAndHint( 104 | "Connection and PDO driver", 105 | "It is ok! Because you are using " . $driverName . ", and it doesn't support PDO driver.", 106 | "" 107 | ); 108 | } else { 109 | } 110 | } else { 111 | try { 112 | $serverVersion = $dbConnection->getPDO()->getAttribute(\PDO::ATTR_SERVER_VERSION); 113 | $results->add( 114 | "Server version", 115 | $serverVersion 116 | ); 117 | } catch (\PDOException $e) { 118 | $results->addErrorAndHint( 119 | "Error DB", 120 | $e->getMessage(), 121 | "Check out your .env file for these parameters: DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD" 122 | ); 123 | $results = $this->getConfigsDatabase($results); 124 | $results = $this->getConfigsDatabaseFromEnv($results); 125 | return $results; 126 | } 127 | 128 | 129 | $connectionType = $dbConnection->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME); 130 | $results->add( 131 | "Database connection type", 132 | $connectionType 133 | ); 134 | $stringTables = ""; 135 | $stringTables = match ($connectionType) { 136 | 'mysql' => $this->getTablesListMysql(), 137 | 'sqlite' => $this->getTablesListSqlite(), 138 | default => "<>", 139 | }; 140 | $results->add( 141 | "Tables", 142 | $stringTables 143 | ); 144 | 145 | $checkCountMessage = ""; 146 | $checkCount = 0; 147 | try { 148 | $checkCount = DB::table($checkTable) 149 | ->select(DB::raw('*')) 150 | ->count(); 151 | } catch (\Exception) { 152 | $checkCount = 0; 153 | $checkCountMessage = " - error with " . $checkTable . " table"; 154 | $results->addErrorAndHint( 155 | "Table Error", 156 | "Failed query, table <" . $checkTable . "> ", 157 | "Make sure that table <" . $checkTable . 158 | "> exists, available tables : " . 159 | (($stringTables == "") ? "Not tables found" : $stringTables) 160 | ); 161 | } 162 | 163 | $results->add( 164 | "Query Table", 165 | $checkTable 166 | ); 167 | $results->add( 168 | "Number of rows", 169 | $checkCount . $checkCountMessage 170 | ); 171 | if ($checkCount > 0) { 172 | try { 173 | $latest = DB::table($checkTable)->latest($columnSorting)->first(); 174 | $results->add( 175 | "LAST row in table", 176 | json_encode($latest, JSON_THROW_ON_ERROR) 177 | ); 178 | } catch (QueryException) { 179 | $results->addErrorAndHint( 180 | "Table Error", 181 | "Failed query, table <" . $checkTable . "> column <" . $columnSorting . ">", 182 | "Make sure that table <" . $checkTable . "> column <" . $columnSorting . "> exists" 183 | ); 184 | } 185 | } 186 | } 187 | } 188 | 189 | public function getDatabase($checkTable = "users", $columnSorting = "created_at"): \HiFolks\LaraLens\ResultLens 190 | { 191 | $results = new ResultLens(); 192 | 193 | $dbConnection = $this->dbConnection(); 194 | 195 | 196 | $results->add( 197 | "Database default", 198 | config("database.default") 199 | ); 200 | if ($dbConnection) { 201 | $this->getDatabaseConnectionInfos($dbConnection, $results, $checkTable, $columnSorting); 202 | } 203 | 204 | 205 | 206 | 207 | 208 | return $results; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LaraLens 2 | 3 | 4 | ![CI/CD Github Actions](https://img.shields.io/github/actions/workflow/status/hi-folks/lara-lens/php-code-quality.yml?style=for-the-badge) 5 | ![GitHub last commit](https://img.shields.io/github/last-commit/hi-folks/lara-lens?style=for-the-badge) 6 | ![GitHub Release Date](https://img.shields.io/github/release-date/hi-folks/lara-lens?style=for-the-badge) 7 | ![Packagist PHP Version](https://img.shields.io/packagist/v/hi-folks/lara-lens?style=for-the-badge) 8 | 9 | 10 | ![LaraLens](https://raw.githubusercontent.com/Hi-Folks/lara-lens/develop/LaraLens-Laravel-Artisan.png) 11 | 12 | ## What 13 | **LaraLens** is a _Laravel_ artisan command to show you the current configuration of your 14 | application. It is useful to show in your terminal the status of: 15 | * some useful configuration variable; 16 | * the database connection; 17 | * the tables in the database; 18 | * the connection via HTTP request; 19 | * the server requirements (PHP version, PHP modules required and installed, Laravel version etc.). 20 | 21 | ![LaraLens - diagnostic package for Laravel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ryagpu0qqwgy476x5w5b.gif) 22 | 23 | 24 | ## Why 25 | When I have a new Laravel Application deployed on the target server, usually I perform a list of commands in order to check the configuration, the connection to database, inspect some tables, the response of the web server. 26 | I tried to show more information in just one command. 27 | This is useful also when the installation of your Laravel application is on premises, and someone else takes care about the configuration. So, in this scenario usually, as developer, your first question is: "how is configured the application?". 28 | 29 | ## Installation 30 | 31 | You can install the package via composer: 32 | 33 | ```shell script 34 | composer require hi-folks/lara-lens 35 | ``` 36 | 37 | The Packagist page is: 38 | https://packagist.org/packages/hi-folks/lara-lens 39 | 40 | ## Usage 41 | 42 | ```shell script 43 | php artisan laralens:diagnostic 44 | ``` 45 | 46 | ### Usage: control database connection 47 | You can see Database Connection information, and you can choose the table to check, and the column used for the "order by" (default created_at): 48 | ```shell script 49 | php artisan laralens:diagnostic --table=migrations --column-sort=id 50 | ``` 51 | To take the last **created** user: 52 | ```shell script 53 | php artisan laralens:diagnostic --table=users --column-sort=created_at 54 | ``` 55 | To take the last **updated** user: 56 | ```shell script 57 | php artisan laralens:diagnostic --table=users --column-sort=updated_at 58 | ``` 59 | 60 | ### Usage: control the output 61 | You can control the output via the _show_ option. You can define: 62 | 63 | * config 64 | * connection 65 | * database 66 | * runtime 67 | * migration 68 | * php-ext 69 | * php-ini 70 | * all 71 | 72 | The default for _--show_ option (if you avoid specifying _--show_) is to display: config, connection, database, runtime, migration. 73 | 74 | 75 | ```shell script 76 | php artisan laralens:diagnostic --show=config --show=connection --show=database --show=runtime --show=migration 77 | ``` 78 | 79 | If you want to see only database information: 80 | 81 | ```shell script 82 | php artisan laralens:diagnostic --show=database 83 | ``` 84 | 85 | If you want to see a verbose output (with also PHP extensions and PHP INI values): 86 | 87 | ```shell script 88 | php artisan laralens:diagnostic --show=all 89 | ``` 90 | or better: 91 | ```shell script 92 | php artisan laralens:diagnostic --all 93 | ``` 94 | 95 | 96 | If you want to see only PHP extensions: 97 | ```shell script 98 | php artisan laralens:diagnostic --show=php-ext 99 | ``` 100 | 101 | If you want to see only PHP INI values: 102 | ```shell script 103 | php artisan laralens:diagnostic --show=php-ini 104 | ``` 105 | 106 | ### Usage: skip database connection and database diagnostics 107 | If your Laravel application doesn't use the database, you can skip the database inspection with --skip-database option. 108 | 109 | ```shell script 110 | php artisan laralens:diagnostic --skip-database 111 | ``` 112 | 113 | ### Usage: show some oprating system information 114 | You can show some operating system information like: 115 | - PHP script owner's UID 116 | - Current User 117 | - Operating System 118 | - Hostname 119 | - Release name 120 | - Machine Name 121 | - Version info 122 | 123 | using _"--show os"_ option or _"--show all"_ option 124 | ```shell 125 | php artisan laralens:diagnostic --show os 126 | ``` 127 | 128 | ### Usage: change the style of output table 129 | You can choose one of these styles via *--style=* option: 130 | 131 | * default 132 | * borderless 133 | * compact 134 | * symfony-style-guide 135 | * box 136 | * box-double 137 | 138 | For example: 139 | ```sh 140 | php artisan laralens:diagnostic --style=borderless 141 | ``` 142 | 143 | ### Usage: change the width of the output table 144 | To use 120 characters (wide terminal), you can use --large option 145 | ```sh 146 | php artisan laralens:diagnostic --large 147 | ``` 148 | 149 | 150 | ### Testing 151 | 152 | ``` bash 153 | composer test 154 | ``` 155 | 156 | ### Changelog 157 | 158 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 159 | 160 | ## Usage as Web Page 161 | 162 | LaraLens provides information with the command line via terminal as shown above. 163 | You have also the opportunity to see the information via your web browser. 164 | You can enable web view via the configuration. 165 | 166 | Publish default configuration for LaraLens in your Laravel Application: 167 | ```shell script 168 | php artisan vendor:publish --provider="HiFolks\LaraLens\LaraLensServiceProvider" --tag="config" 169 | ``` 170 | 171 | After that,you will have a new configuration file in your config directory. The file is: config/lara-lens.php 172 | 173 | Add `LARALENS_WEB_ENABLED=on` option to your .env file. You may also override the default parameters for `LARALENS_PREFIX` and `LARALENS_MIDDLEWARE` 174 | ``` 175 | # Wether Web Report should be enabled or not 176 | LARALENS_WEB_ENABLED=on 177 | # Path prefix in order to acess the Web Report via browser 178 | LARALENS_PREFIX="laralens" 179 | # Which middleware should be used when acessing the Web Report, separete more with ; 180 | LARALENS_MIDDLEWARE="web;auth.basic" 181 | ``` 182 | 183 | For example, with the configuration above you would have enabled the web view (_web-enabled_ parameter) under _/laralens_test/_ path and with the `web` and `auth.basic` middleware 184 | 185 | ```php 186 | return [ 187 | 'prefix' => env('LARALENS_PREFIX', 'laralens'), // URL prefix (default=laralens) 188 | 'middleware' => explode(';', env('LARALENS_MIDDLEWARE', 'web')), // middleware (default=web) more separate with ; 189 | 'web-enabled' => env('LARALENS_WEB_ENABLED', 'off') // Activate web view (default=off) 190 | ]; 191 | ``` 192 | 193 | ### Web view configuration hint 194 | LaraLens shows some internal configuration of your Laravel application, so I suggest you to disable it in a production environment. 195 | To disable LaraLens web view, make sure to remove LARALENS_WEB_ENABLED config from .env file or set it to _off_ 196 | ``` 197 | LARALENS_WEB_ENABLED=off 198 | ``` 199 | 200 | 201 | 202 | 203 | ## Contributing 204 | 205 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 206 | 207 | ### Submit ideas or feature requests or issues 208 | 209 | * Take a look if your request is already there [https://github.com/Hi-Folks/lara-lens/issues](https://github.com/Hi-Folks/lara-lens/issues) 210 | * If it is not present, you can create a new one [https://github.com/Hi-Folks/lara-lens/issues/new](https://github.com/Hi-Folks/lara-lens/issues/new) 211 | 212 | 213 | ## Credits 214 | 215 | - [Roberto Butti](https://github.com/hi-folks) 216 | - [All Contributors](https://github.com/Hi-Folks/lara-lens/graphs/contributors) 217 | - [Laravel Package Boilerplate](https://laravelpackageboilerplate.com) 218 | 219 | ## Who talks about LaraLens 220 | - [Laravel News](https://laravel-news.com/inspect-application-configuration-with-laralens) 221 | - [Medium Article](https://levelup.gitconnected.com/laralens-a-laravel-command-for-inspecting-configuration-2bbb4e714cf7) 222 | 223 | ## License 224 | 225 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 226 | -------------------------------------------------------------------------------- /src/Console/LaraLensCommand.php: -------------------------------------------------------------------------------- 1 | info(json_encode(config()->all(), JSON_PRETTY_PRINT)); 56 | } 57 | 58 | private function overview($checkTable = "users", $columnSorting = "created_at", $show = self::OPTION_SHOW_ALL): void 59 | { 60 | $ll = new LaraLens(); 61 | if ($show & self::OPTION_SHOW_CONFIGS) { 62 | $output = $ll->getConfigs(); 63 | $this->printOutputTerm("Config keys via config()", $output->toArray()); 64 | } 65 | if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { 66 | $output = $ll->getRuntimeConfigs(); 67 | $this->printOutputTerm("Runtime Configs", $output->toArray()); 68 | $output = $ll->checkServerRequirements(); 69 | $this->printOutputTerm("Laravel Requirements", $output->toArray()); 70 | } 71 | if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { 72 | $output = $ll->checkFiles(); 73 | $this->printOutputTerm("Check files", $output->toArray()); 74 | } 75 | if ($show & self::OPTION_SHOW_CONNECTIONS) { 76 | $output = $ll->getConnections($this->urlPath); 77 | $this->printOutputTerm("Connections", $output->toArray()); 78 | } 79 | if ($show & self::OPTION_SHOW_DATABASE) { 80 | $output = $ll->getDatabase($checkTable, $columnSorting); 81 | $this->printOutputTerm("Database", $output->toArray()); 82 | } 83 | if ($show & self::OPTION_SHOW_MIGRATION) { 84 | try { 85 | $this->call('migrate:status'); 86 | } catch (\Exception $e) { 87 | $r = new ResultLens(); 88 | $r->add( 89 | "Check migrate status", 90 | "Error in check migration" 91 | ); 92 | $ll->checksBag->addErrorAndHint( 93 | "Migration status", 94 | $e->getMessage(), 95 | "Check the Database configuration" 96 | ); 97 | $this->printOutputTerm("Migration", $r->toArray()); 98 | } 99 | } 100 | if ($show & self::OPTION_SHOW_PHPEXTENSIONS) { 101 | $output = $ll->getPhpExtensions(); 102 | $this->printOutputTerm("PHP Extensions", $output->toArray()); 103 | } 104 | if ($show & self::OPTION_SHOW_PHPINIVALUES) { 105 | $output = $ll->getPhpIniValues(); 106 | $this->printOutputTerm("PHP ini config", $output->toArray()); 107 | } 108 | if ($show & self::OPTION_SHOW_OS) { 109 | $output = $ll->getOsConfigs(); 110 | $this->printOutputTerm("Operating System", $output->toArray()); 111 | } 112 | $this->printChecksTerm($ll->checksBag->toArray()); 113 | } 114 | 115 | 116 | public function handle(): void 117 | { 118 | $op = $this->argument("op"); 119 | $checkTable = $this->option("table"); 120 | $styleTable = $this->option("style"); 121 | $show = self::OPTION_SHOW_DEFAULT; 122 | if (in_array($styleTable, explode("|", self::TABLE_STYLES))) { 123 | $this->styleTable = $styleTable; 124 | } else { 125 | $this->styleTable = self::DEFAULT_STYLE; 126 | } 127 | $columnSorting = $this->option("column-sort"); 128 | $showOptions = $this->option("all") ? ['all'] : $this->option("show"); 129 | 130 | 131 | if (is_array($showOptions)) { 132 | if (count($showOptions) > 0) { 133 | $show = self::OPTION_SHOW_NONE; 134 | if (in_array("all", $showOptions)) { 135 | $show = self::OPTION_SHOW_ALL; 136 | } else { 137 | $show = (in_array("config", $showOptions)) ? $show | self::OPTION_SHOW_CONFIGS : $show ; 138 | $show = (in_array("runtime", $showOptions)) ? $show | self::OPTION_SHOW_RUNTIMECONFIGS : $show ; 139 | $show = (in_array("connection", $showOptions)) ? $show | self::OPTION_SHOW_CONNECTIONS : $show ; 140 | $show = (in_array("database", $showOptions)) ? $show | self::OPTION_SHOW_DATABASE : $show ; 141 | $show = (in_array("migration", $showOptions)) ? $show | self::OPTION_SHOW_MIGRATION : $show ; 142 | $show = (in_array("php-ext", $showOptions)) ? $show | self::OPTION_SHOW_PHPEXTENSIONS : $show ; 143 | $show = (in_array("php-ini", $showOptions)) ? $show | self::OPTION_SHOW_PHPINIVALUES : $show ; 144 | $show = (in_array("os", $showOptions)) ? $show | self::OPTION_SHOW_OS : $show ; 145 | } 146 | } else { 147 | $show = self::OPTION_SHOW_DEFAULT; 148 | } 149 | } 150 | $skipDatabases = $this->option("skip-database"); 151 | if ($skipDatabases) { 152 | $show = $show - self::OPTION_SHOW_DATABASE - self::OPTION_SHOW_MIGRATION; 153 | } 154 | 155 | $this->widthLabel = $this->option("width-label"); 156 | $this->widthValue = $this->option("width-value"); 157 | if ($this->option("large")) { 158 | $this->widthValue = self::DEFAULT_LARGE_WIDTH; 159 | } 160 | 161 | $this->urlPath = $this->option("url-path"); 162 | if (is_null($this->urlPath)) { 163 | $this->urlPath = self::DEFAULT_PATH; 164 | } 165 | $version = \Composer\InstalledVersions::getPrettyVersion('hi-folks/lara-lens'); 166 | $this->title("Laralens (" . $version . ")"); 167 | match ($op) { 168 | 'overview' => $this->overview($checkTable, $columnSorting, $show), 169 | 'allconfigs' => $this->allConfigs(), 170 | default => $this->info("What you mean? try with 'php artisan laralens:diagnostic --help'"), 171 | }; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.0.1 - 2024-11-29 4 | - Upgrade to PHP 8.4 5 | 6 | ## 1.0.0 - 2024-03-13 7 | - upgrading packages 8 | 9 | ## 0.5.2 - 2024-03-12 10 | - Updating hints for missing lang directory 11 | 12 | ## 0.5.1 - 2024-03-07 13 | - Detect dependencies for Laravel 11 14 | 15 | ## 0.5.0 - 2024-03-07 16 | - Support for Laravel 11 17 | 18 | ## 0.4.1 - 2023-11-18 19 | - Testing with PHP 8.3 20 | - Adding title helper in the TermOutput 21 | - Adding RectorPHP in the code quality tools 22 | 23 | ## 0.4.0 - 2023-02-04 24 | - Support for Laravel 10 25 | - Add requirements check for Laravel 10 26 | - GitHub Actions Workflows: cleaning and fine-tuning 27 | - Using Pint for Check styleguide (PSR12) 28 | - Using PestPHP for testing 29 | - Removing Makefile and using composer scripts to launching code quality tools 30 | - migrating tests from PHPUnit to PestPHP, thanks to @dansysanalyst 31 | - Fix skip-database option, now with works with all "show" options. Before the fix it worked only with "show all" option. 32 | 33 | ## 0.3.1- 2022-07-17 34 | - Fine tuning dependencies for PHP 8.1, and Symfony / Doctrine packages 35 | - Drop supprt for PHP7.4, for older PHP and Laravel, use Laralens v0.2.x 36 | 37 | 38 | ## 0.3.0 - 2022-07-17 39 | - Add Termwind package 40 | - Review console output, thanks also to @exodusanto 41 | - Support for PHP 8.0 and greater 42 | 43 | ## 0.2.7 - 2022-01-23 44 | - Add Support for Laravel 9 45 | - Add tests for PHP8.1 46 | - Drop support for PHP7.3 47 | - Some fine tuning for Static Code analysis 48 | 49 | ## 0.2.6 - 2021-10-03 50 | Hacktoberfest!!! 51 | We would like to say thank you to @tweichart and @martijnengler for the contributions. 52 | ### Add 53 | - Add --all option for showing all information (verbose output). Thanks to @tweichart 54 | - Add --large option for using 120 chars width. Thanks to @martijnengler 55 | 56 | ## 0.2.5 - 2021-06-18 57 | ### Add 58 | - Add some Operating System information: 59 | - PHP script owner's UID 60 | - Current User 61 | - Operating System 62 | - Hostname 63 | - Release name 64 | - Machine Name 65 | - Version info 66 | 67 | ## 0.2.4 - 2021-04-18 68 | ### Add 69 | - In runtime information, added upload_max_filesize and post_max_size from php configuration ( thanks to @yogendra-revanna ) 70 | 71 | ## 0.2.3 - 2021-04-10 72 | ### Add 73 | - Check DEBUG and ENV configuration for production (if production avoid having debug on); 74 | - Check Storage Links and show the user a waring if some directory links are missing 75 | 76 | ### Change 77 | - improve tests and checks script for Workflows 78 | 79 | ## 0.2.2 - 2020-11-05 80 | ### Add 81 | - Add configuration parameters (config/lara-lens.php) for managing webview: LARALENS_PREFIX, LARALENS_MIDDLEWARE, LARALENS_WEB_ENABLED, thanks to @yogendra-revanna, @JexPY, @Zuruckt; 82 | - Initial support for PHP8-rc; 83 | 84 | 85 | 86 | ## 0.2.1 - 2020-09-22 87 | ### Add 88 | - Show available PHP extension via --show=php-ext option (thanks to https://github.com/yogendra-revanna); 89 | - Show PHP ini configuration via --show=php-ini (thanks to https://github.com/yogendra-revanna). 90 | 91 | ### Change 92 | - Managing default show options. Before this change the default was to show all options. Now we have a lot of option to show (also the long list of PHP extension and PHP ini configuration), so by default LaraLens shows: configuration, runtime, HTTP connection, database, migrations. 93 | 94 | ## 0.2.0 - 2020-09-20 95 | ### Add 96 | - You can watch your LaraLens report with your browser (not just with your terminal); 97 | - Makefile to manage development tasks; 98 | - Add a _timeout_ when checking HTTP connection; 99 | - CI/CD: Add Caching vendors in GitHub actions pipeline. 100 | 101 | ### Change 102 | - DOCS: Update README, add some docs about skip database connection and database. 103 | 104 | ## 0.1.20 - 2020-09-11 105 | ### Fix 106 | Thanks to [phpstan](https://github.com/phpstan/phpstan) : 107 | - using $line instead of $row 108 | - initialize correctly $show 109 | - re throw exception for HTTP connection 110 | 111 | 112 | ## 0.1.19 - 2020-09-11 113 | ### Add 114 | - Add --skip-database in order to execute all checks except database and migration status (it is useful for example if the application it doesn't need the database); 115 | 116 | ### Change 117 | - Code more PSR2 compliant (phpcs); 118 | - Fix LaraHttpResponse::status(). The method returns the http status code. Close #19 119 | 120 | 121 | ## 0.1.18 - 2020-09-05 122 | ### Add 123 | - Support for Laravel 8 124 | 125 | ## 0.1.17 - 2020-08-30 126 | ### Add 127 | - Adding support for Laravel 6 128 | - Check server requirements for PHP modules needed by Laravel; 129 | - Check server requirements for PHP Version (based on the Laravel version); 130 | - Adding PORT display for Database connection; 131 | - List PHP modules installed, needed by Laravel; 132 | 133 | ### Change 134 | - Updating test cases 135 | 136 | ## 0.1.16 - 2020-08-19 137 | ### Add 138 | - Adding php linter in CI/CD. We use php 7.2 linter for incoming support to Laravel 6. 139 | ### Fix 140 | - Fix syntax in DatabaseLens.php. Close #17 ; 141 | 142 | ## 0.1.15 - 2020-08-09 143 | 144 | ### Add 145 | - Add --url-path for using a specific path during HTTP connection. For example --url-path=test (for checking "test" path) 146 | ### Change 147 | - Refactor logic with traits for: database connection, configuration, runtime parameters, filesystem, http connections (issue #11); 148 | - Improve the HTTP Connection check (configuration url, url generated) 149 | 150 | 151 | ## 0.1.14 - 2020-08-04 152 | 153 | - Refactoring "check" functionality 154 | - add warning messages 155 | - show report check 156 | - add alert green 157 | - managing multiple type of message (warning / error / hint) 158 | - try catch for db connection, for checking files, for scanning directories 159 | - check PDO for database connection 160 | 161 | 162 | ## 0.1.13 - 2020-07-31 163 | 164 | ### Add 165 | - Add hints for database tables (table exists, column exists) 166 | ### Change 167 | - Fix typo in banner. ( close #6 ) 168 | - updated tests 169 | 170 | 171 | ## 0.1.12 - 2020-07-25 172 | 173 | ### Add 174 | - When a check is not working properly, now it is displayed some hints; 175 | - Add hints for database connection; 176 | - Add hints for HTTP connections. 177 | 178 | ## 0.1.11 - 2020-07-12 179 | 180 | ### Add 181 | 182 | ### Change 183 | - Improved list of languages; 184 | - Update readme 185 | 186 | ## 0.1.10 - 2020-06-25 187 | 188 | ### Add 189 | New function for check files. 190 | - check .env file 191 | - check language storage 192 | - list languages available 193 | 194 | ## 0.1.9 - 2020-06-18 195 | 196 | ### Add 197 | 198 | New runtime config about some paths: 199 | 200 | * "langPath" =>"Path to the language files", 201 | * "publicPath" =>" Path to the public / web directory", 202 | * "storagePath" => "Storage directory", 203 | * "resourcePath" =>"Resources directory", 204 | * "getCachedServicesPath" => "Path to the cached services.php", 205 | * "getCachedPackagesPath" => "Path to the cached packages.php", 206 | * "getCachedConfigPath" => "Path to the configuration cache", 207 | * "getCachedRoutesPath" => "Path to the routes cache", 208 | * "getCachedEventsPath" => "Path to the events cache file", 209 | * "getNamespace" => "Application namespace" 210 | 211 | ## 0.1.8 - 2020-06-18 212 | 213 | ### Add 214 | 215 | :nail_care: Style output table via --style option. You can choose one of these styles (box-double is the default used by LaraLens): 216 | * default 217 | * borderless 218 | * compact 219 | * symfony-style-guide 220 | * box 221 | * box-double 222 | 223 | :eyeglasses: Runtime config: 224 | * environmentPath 225 | * environmentFile 226 | * environmentFilePath 227 | 228 | ### Change 229 | 230 | * Refactor for App::"function"() 231 | * update tests 232 | * update readme 233 | * update help (-h) 234 | 235 | ## 0.1.7 - 2020-06-16 236 | 237 | ### Add 238 | 239 | Database connection: 240 | * connection name 241 | * getQueryGrammar 242 | * getDriverName 243 | * getDatabaseName 244 | * getTablePrefix 245 | * database server version 246 | 247 | Runtime configuration: 248 | * Laravel version 249 | * PHP version 250 | 251 | ## 0.1.6 - 2020-06-01 252 | 253 | ### Add 254 | 255 | * Add show option --show (all|config|runtime|connection|database|migration) 256 | 257 | ## 0.1.5 - 2020-05-29 258 | 259 | ### Improve 260 | 261 | * managing a better output 262 | * extracting long message from tables 263 | * settings width for columns tables 264 | 265 | 266 | ## 0.1.4 - 2020-05-28 267 | 268 | ### Fix 269 | 270 | * Catch HTTP connection exception 271 | 272 | ## 0.1.3 - 2020-05-27 273 | 274 | ### Add 275 | 276 | * detect DB connection type; 277 | * get tables for mysql; 278 | * get tables for sqlite; 279 | * count and retrieve last row from a table. Table and column name are as input parameters; 280 | * test database diagnostics; 281 | * update readme for documentation. 282 | 283 | 284 | ## 0.1.2 - 2020-05-22 285 | 286 | ### Add 287 | 288 | * Add new argument as input (it is optional): 289 | - overview: you can see configuration, http connection, db connection etc.; 290 | - allconfigs: you can see the verbose configuration from Laravel application. Try to use 'php artisan laralens:diagnostic allconfigs' in your laravel application. You will see the dump of all configuration parameters in json format. 291 | 292 | ## 0.1.1 - 2020-05-22 293 | 294 | ### Add 295 | 296 | * Add runtime config: 297 | * App::getLocale() 298 | * App::environment()) 299 | * Generated url via asset() and url() helpers 300 | * Invoke migrate:status 301 | 302 | ## 0.1.0 - 2020-05-21 303 | 304 | * :tada: initial release 305 | * Add laralens:diagnostic artisan command (Laravel) 306 | * Check config parameter like app.url, app.locale, app.url and database.* 307 | * Check the http connection with "app.url" defined in base configuration 308 | * Check the connection with DB and counts the row for a specific table (users by default) 309 | -------------------------------------------------------------------------------- /src/Lens/Traits/RuntimeLens.php: -------------------------------------------------------------------------------- 1 | $label) { 15 | $value = call_user_func("App::" . $function); 16 | if (Str::length($curDir) > 3) { 17 | if (Str::startsWith($value, $curDir)) { 18 | $value = "." . Str::after($value, $curDir); 19 | } 20 | } 21 | $results->add( 22 | $label, 23 | $value 24 | ); 25 | } 26 | } 27 | 28 | private function getIniValues($results): void 29 | { 30 | $labels = [ 31 | "post_max_size", 32 | "upload_max_filesize", 33 | ]; 34 | foreach ($labels as $label) { 35 | $results->add( 36 | $label, 37 | ini_get($label) 38 | ); 39 | } 40 | } 41 | 42 | public function getRuntimeConfigs(): \HiFolks\LaraLens\ResultLens 43 | { 44 | $results = new ResultLens(); 45 | $results->add( 46 | "PHP Version", 47 | phpversion() 48 | ); 49 | $this->getIniValues($results); 50 | $results->add( 51 | "Current Directory", 52 | getcwd() 53 | ); 54 | $this->appCaller( 55 | $results, 56 | [ 57 | "version" => "Laravel Version", 58 | "getLocale" => "Locale", 59 | "getNamespace" => "Application namespace", 60 | "environment" => "Environment", 61 | "environmentPath" => "Environment file directory", 62 | "environmentFile" => "Environment file used", 63 | "environmentFilePath" => "Full path to the environment file", 64 | "langPath" => "Path to the language files", 65 | "publicPath" => "Path to the public / web directory", 66 | "storagePath" => "Storage directory", 67 | "resourcePath" => "Resources directory", 68 | "getCachedServicesPath" => "Path to the cached services.php", 69 | "getCachedPackagesPath" => "Path to the cached packages.php", 70 | "getCachedConfigPath" => "Path to the configuration cache", 71 | "getCachedRoutesPath" => "Path to the routes cache", 72 | "getCachedEventsPath" => "Path to the events cache file" 73 | ] 74 | ); 75 | $results->add( 76 | "Generated url for / ", 77 | url("/") 78 | ); 79 | $results->add( 80 | "Generated asset url for /test.js ", 81 | asset("/test.js") 82 | ); 83 | return $results; 84 | } 85 | 86 | public function checkServerRequirements(): \HiFolks\LaraLens\ResultLens 87 | { 88 | $results = new ResultLens(); 89 | 90 | $phpVersion = phpversion(); 91 | $laravelVersion = app()->version(); 92 | $laravelMajorVersion = Arr::get(explode('.', $laravelVersion), 0, "8"); 93 | 94 | $phpExtensionRequirements = [ 95 | "6" => [ 96 | "phpversion" => "7.2.0", 97 | "extensions" => [ 98 | "bcmath", 99 | "ctype", 100 | "fileinfo", 101 | "json", 102 | "mbstring", 103 | "openssl", 104 | "pdo", 105 | "tokenizer", 106 | "xml" 107 | ] 108 | ], 109 | "7" => [ 110 | "phpversion" => "7.2.5", 111 | "extensions" => [ 112 | "bcmath", 113 | "ctype", 114 | "fileinfo", 115 | "json", 116 | "mbstring", 117 | "openssl", 118 | "pdo", 119 | "tokenizer", 120 | "xml" 121 | ] 122 | ], 123 | "8" => [ 124 | "phpversion" => "7.3.0", 125 | "extensions" => [ 126 | "bcmath", 127 | "ctype", 128 | "fileinfo", 129 | "json", 130 | "mbstring", 131 | "openssl", 132 | "pdo", 133 | "tokenizer", 134 | "xml" 135 | ] 136 | ], 137 | "9" => [ 138 | "phpversion" => "8.0.2", 139 | "extensions" => [ 140 | "bcmath", 141 | "ctype", 142 | "fileinfo", 143 | "json", 144 | "mbstring", 145 | "openssl", 146 | "pdo", 147 | "tokenizer", 148 | "xml" 149 | ] 150 | ], 151 | "10" => [ 152 | "phpversion" => "8.1.0", 153 | "extensions" => [ 154 | "bcmath", 155 | "ctype", 156 | "curl", 157 | "dom", 158 | "fileinfo", 159 | "json", 160 | "mbstring", 161 | "openssl", 162 | "pcre", 163 | "pdo", 164 | "tokenizer", 165 | "xml" 166 | ] 167 | ], 168 | "11" => [ 169 | "phpversion" => "8.2.0", 170 | "extensions" => [ 171 | "ctype", 172 | "curl", 173 | "dom", 174 | "fileinfo", 175 | "filter", 176 | "json", 177 | "libxml", 178 | "mbstring", 179 | "openssl", 180 | "pcre", 181 | "phar", 182 | "reflection", 183 | "simplexml", 184 | "spl", 185 | "tokenizer", 186 | "xml", 187 | "xmlwriter" 188 | ] 189 | ] 190 | 191 | ]; 192 | if (!key_exists($laravelMajorVersion, $phpExtensionRequirements)) { 193 | $laravelMajorVersion = "11"; 194 | } 195 | $phpVersionRequired = $phpExtensionRequirements[$laravelMajorVersion]["phpversion"]; 196 | $results->add( 197 | "Laravel version", 198 | $laravelVersion . " ( " . $laravelMajorVersion . " )" 199 | ); 200 | $results->add( 201 | "PHP version", 202 | $phpVersion 203 | ); 204 | $results->add( 205 | "PHP version required (min)", 206 | $phpVersionRequired 207 | ); 208 | 209 | $helpInstall = [ 210 | "bcmath" => "BCMath Arbitrary Precision Mathematics: https://www.php.net/manual/en/bc.setup.php", 211 | "ctype" => "Character type checking: https://www.php.net/manual/en/book.ctype", 212 | "curl" => "Client URL Library: https://www.php.net/manual/en/book.curl.php", 213 | "dom" => "Document Object Model: https://www.php.net/manual/en/book.dom.php", 214 | "fileinfo" => "File Information: https://www.php.net/manual/en/book.fileinfo", 215 | "filter" => "Data Filtering: https://www.php.net/manual/en/book.filter.php", 216 | "json" => "JavaScript Object Notation: https://www.php.net/manual/en/book.json", 217 | "libxml" => "libxml: https://www.php.net/manual/en/book.libxml.php", 218 | "mbstring" => "Multibyte string: https://www.php.net/manual/en/book.mbstring.php", 219 | "openssl" => "OpenSSL: https://www.php.net/manual/en/book.openssl.php", 220 | "pcre" => "Regular Expressions (Perl-Compatible): https://www.php.net/manual/en/book.pcre.php", 221 | "pdo" => "PHP Data Objects: https://www.php.net/manual/en/book.pdo.php", 222 | "phar" => "Phar: https://www.php.net/manual/en/book.phar.php", 223 | "reflection" => "Reflection: https://www.php.net/manual/en/book.reflection.php", 224 | "simplexml" => "SimpleXML: https://www.php.net/manual/en/book.simplexml.php", 225 | "spl" => "Standard PHP Library (SPL): https://www.php.net/manual/en/book.spl.php", 226 | "tokenizer" => "Tokenizer: https://www.php.net/manual/en/book.tokenizer.php", 227 | "xml" => "XML Parser: https://www.php.net/manual/en/book.xml.php", 228 | "xmlwriter" => "XMLWriter: https://www.php.net/manual/en/book.xmlwriter.php" 229 | ]; 230 | $modulesOk = []; 231 | $modulesNotok = []; 232 | foreach ($phpExtensionRequirements[$laravelMajorVersion]["extensions"] as $p) { 233 | if (extension_loaded($p)) { 234 | $modulesOk[] = $p; 235 | } else { 236 | $modulesNotok[] = $p; 237 | } 238 | } 239 | //*** CHECK PHP VERSION 240 | if (version_compare($phpVersion, $phpVersionRequired) < 0) { 241 | $this->checksBag->addWarningAndHint( 242 | "PHP (" . $phpVersion . ") version check", 243 | "PHP version required: " . $phpVersionRequired . ", you have: " . $phpVersion, 244 | "You need to install PHP version: " . $phpVersionRequired 245 | ); 246 | } 247 | $results->add( 248 | "PHP (" . $phpVersion . ") version check", 249 | "PHP version required: " . $phpVersionRequired . ", you have: " . $phpVersion 250 | ); 251 | $results->add( 252 | "PHP extensions installed", 253 | implode(",", $modulesOk) 254 | ); 255 | if (count($modulesNotok) > 0) { 256 | $stringHint = "Please install these modules :" . PHP_EOL; 257 | foreach ($modulesNotok as $pko) { 258 | if (key_exists($pko, $helpInstall)) { 259 | $stringHint = $pko . " : " . $helpInstall[$pko] . PHP_EOL; 260 | } else { 261 | $stringHint = $pko . PHP_EOL; 262 | } 263 | } 264 | $this->checksBag->addWarningAndHint( 265 | "PHP extensions missing", 266 | "Some PHP Extensions are missing", 267 | $stringHint 268 | ); 269 | } else { 270 | $results->add( 271 | "PHP extension installed", 272 | "Looks good for Laravel " . $laravelMajorVersion 273 | ); 274 | } 275 | return $results; 276 | } 277 | 278 | public function getPhpExtensions(): \HiFolks\LaraLens\ResultLens 279 | { 280 | $results = new ResultLens(); 281 | foreach (get_loaded_extensions() as $name) { 282 | $results->add( 283 | $name, 284 | "" 285 | ); 286 | } 287 | return $results; 288 | } 289 | 290 | public function getPhpIniValues(): \HiFolks\LaraLens\ResultLens 291 | { 292 | $results = new ResultLens(); 293 | foreach (ini_get_all() as $name => $row) { 294 | $results->add( 295 | $name, 296 | $row['local_value'] 297 | ); 298 | } 299 | return $results; 300 | } 301 | } 302 | --------------------------------------------------------------------------------