Repository: Hi-Folks/lara-lens Branch: develop Commit: f323ffc47f52 Files: 42 Total size: 85.6 KB Directory structure: gitextract_66wvtac2/ ├── .editorconfig ├── .gitattributes ├── .github/ │ └── workflows/ │ ├── php-code-quality.yml │ └── php-lint.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config/ │ └── config.php ├── phpcs.xml ├── phpstan.neon ├── phpunit.xml.dist ├── phpunit.xml.dist.bak ├── pint.json ├── psalm.xml ├── rector.php ├── resources/ │ └── views/ │ └── laralens/ │ ├── index.blade.php │ └── term/ │ ├── checks.blade.php │ └── table.blade.php ├── routes/ │ └── web.php ├── src/ │ ├── Console/ │ │ └── LaraLensCommand.php │ ├── Http/ │ │ └── Controllers/ │ │ ├── Controller.php │ │ └── LaraLensController.php │ ├── LaraLensFacade.php │ ├── LaraLensServiceProvider.php │ ├── Lens/ │ │ ├── LaraHttp.php │ │ ├── LaraLens.php │ │ ├── Objects/ │ │ │ └── LaraHttpResponse.php │ │ └── Traits/ │ │ ├── BaseTraits.php │ │ ├── ConfigLens.php │ │ ├── DatabaseLens.php │ │ ├── FilesystemLens.php │ │ ├── HttpConnectionLens.php │ │ ├── OperatingSystemLens.php │ │ ├── RuntimeLens.php │ │ └── TermOutput.php │ └── ResultLens.php └── tests/ ├── Feature/ │ └── ConsistencyTest.php ├── Pest.php └── TestCase.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org root = true [*] charset = utf-8 indent_size = 4 indent_style = space end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false ================================================ FILE: .gitattributes ================================================ # Path-based git attributes # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml.dist export-ignore /.scrutinizer.yml export-ignore /tests export-ignore /.editorconfig export-ignore ================================================ FILE: .github/workflows/php-code-quality.yml ================================================ name: Code Quality Workflow on: push: branches: - develop - features/** - feature/** - upgrade/** pull_request: branches: [ develop ] jobs: laravel-tests: strategy: matrix: operating-system: [ubuntu-latest] php-versions: [ '8.4', '8.3', '8.2', '8.1' ] dependency-stability: [ 'prefer-stable','prefer-lowest' ] runs-on: ${{ matrix.operating-system }} name: Test P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} steps: - uses: actions/checkout@v4 - name: Install PHP versions uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Update Dependencies with latest stable if: matrix.dependency-stability == 'prefer-stable' run: composer update --prefer-stable - name: Update Dependencies with lowest stable if: matrix.dependency-stability == 'prefer-lowest' run: composer update --prefer-stable --prefer-lowest # Code quality - name: Execute tests (Unit and Feature tests) via PHPUnit env: SESSION_DRIVER: array run: composer test laravel-check: strategy: matrix: operating-system: [ubuntu-latest] php-versions: [ '8.3' ] runs-on: ${{ matrix.operating-system }} name: Check P${{ matrix.php-versions }} - ${{ matrix.operating-system}} steps: - uses: actions/checkout@v4 - name: Install PHP versions uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Execute Code Sniffer via phpcs run: | composer style-fix - name: Execute Code Static Analysis (PHP Stan + Larastan) run: | composer phpstan ================================================ FILE: .github/workflows/php-lint.yml ================================================ name: PHP Syntax Checker (Lint) on: push: branches: [ develop ] pull_request: branches: [ develop ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Validate composer.json and composer.lock run: composer validate - name: Install dependencies run: composer install --prefer-dist --no-progress - name: Run test suite run: composer run-script test - name: PHP Syntax Checker (Lint) uses: StephaneBour/actions-php-lint@8.3 with: dir: './src' ================================================ FILE: .gitignore ================================================ build docs composer.lock vendor coverage .phpunit.result.cache .phpunit.cache/ .idea .php_cs.cache .vscode ================================================ FILE: CHANGELOG.md ================================================ # Changelog ## 1.0.1 - 2024-11-29 - Upgrade to PHP 8.4 ## 1.0.0 - 2024-03-13 - upgrading packages ## 0.5.2 - 2024-03-12 - Updating hints for missing lang directory ## 0.5.1 - 2024-03-07 - Detect dependencies for Laravel 11 ## 0.5.0 - 2024-03-07 - Support for Laravel 11 ## 0.4.1 - 2023-11-18 - Testing with PHP 8.3 - Adding title helper in the TermOutput - Adding RectorPHP in the code quality tools ## 0.4.0 - 2023-02-04 - Support for Laravel 10 - Add requirements check for Laravel 10 - GitHub Actions Workflows: cleaning and fine-tuning - Using Pint for Check styleguide (PSR12) - Using PestPHP for testing - Removing Makefile and using composer scripts to launching code quality tools - migrating tests from PHPUnit to PestPHP, thanks to @dansysanalyst - Fix skip-database option, now with works with all "show" options. Before the fix it worked only with "show all" option. ## 0.3.1- 2022-07-17 - Fine tuning dependencies for PHP 8.1, and Symfony / Doctrine packages - Drop supprt for PHP7.4, for older PHP and Laravel, use Laralens v0.2.x ## 0.3.0 - 2022-07-17 - Add Termwind package - Review console output, thanks also to @exodusanto - Support for PHP 8.0 and greater ## 0.2.7 - 2022-01-23 - Add Support for Laravel 9 - Add tests for PHP8.1 - Drop support for PHP7.3 - Some fine tuning for Static Code analysis ## 0.2.6 - 2021-10-03 Hacktoberfest!!! We would like to say thank you to @tweichart and @martijnengler for the contributions. ### Add - Add --all option for showing all information (verbose output). Thanks to @tweichart - Add --large option for using 120 chars width. Thanks to @martijnengler ## 0.2.5 - 2021-06-18 ### Add - Add some Operating System information: - PHP script owner's UID - Current User - Operating System - Hostname - Release name - Machine Name - Version info ## 0.2.4 - 2021-04-18 ### Add - In runtime information, added upload_max_filesize and post_max_size from php configuration ( thanks to @yogendra-revanna ) ## 0.2.3 - 2021-04-10 ### Add - Check DEBUG and ENV configuration for production (if production avoid having debug on); - Check Storage Links and show the user a waring if some directory links are missing ### Change - improve tests and checks script for Workflows ## 0.2.2 - 2020-11-05 ### Add - Add configuration parameters (config/lara-lens.php) for managing webview: LARALENS_PREFIX, LARALENS_MIDDLEWARE, LARALENS_WEB_ENABLED, thanks to @yogendra-revanna, @JexPY, @Zuruckt; - Initial support for PHP8-rc; ## 0.2.1 - 2020-09-22 ### Add - Show available PHP extension via --show=php-ext option (thanks to https://github.com/yogendra-revanna); - Show PHP ini configuration via --show=php-ini (thanks to https://github.com/yogendra-revanna). ### Change - 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. ## 0.2.0 - 2020-09-20 ### Add - You can watch your LaraLens report with your browser (not just with your terminal); - Makefile to manage development tasks; - Add a _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. ## 0.1.20 - 2020-09-11 ### Fix Thanks to [phpstan](https://github.com/phpstan/phpstan) : - using $line instead of $row - initialize correctly $show - re throw exception for HTTP connection ## 0.1.19 - 2020-09-11 ### Add - 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); ### Change - Code more PSR2 compliant (phpcs); - Fix LaraHttpResponse::status(). The method returns the http status code. Close #19 ## 0.1.18 - 2020-09-05 ### Add - Support for Laravel 8 ## 0.1.17 - 2020-08-30 ### Add - Adding support for Laravel 6 - Check server requirements for PHP modules needed by Laravel; - Check server requirements for PHP Version (based on the Laravel version); - Adding PORT display for Database connection; - List PHP modules installed, needed by Laravel; ### Change - Updating test cases ## 0.1.16 - 2020-08-19 ### Add - Adding php linter in CI/CD. We use php 7.2 linter for incoming support to Laravel 6. ### Fix - Fix syntax in DatabaseLens.php. Close #17 ; ## 0.1.15 - 2020-08-09 ### Add - Add --url-path for using a specific path during HTTP connection. For example --url-path=test (for checking "test" path) ### Change - Refactor logic with traits for: database connection, configuration, runtime parameters, filesystem, http connections (issue #11); - Improve the HTTP Connection check (configuration url, url generated) ## 0.1.14 - 2020-08-04 - Refactoring "check" functionality - add warning messages - show report check - add alert green - managing multiple type of message (warning / error / hint) - try catch for db connection, for checking files, for scanning directories - check PDO for database connection ## 0.1.13 - 2020-07-31 ### Add - Add hints for database tables (table exists, column exists) ### Change - Fix typo in banner. ( close #6 ) - updated tests ## 0.1.12 - 2020-07-25 ### Add - When a check is not working properly, now it is displayed some hints; - Add hints for database connection; - Add hints for HTTP connections. ## 0.1.11 - 2020-07-12 ### Add ### Change - Improved list of languages; - Update readme ## 0.1.10 - 2020-06-25 ### Add New function for check files. - check .env file - check language storage - list languages available ## 0.1.9 - 2020-06-18 ### Add New runtime config about some paths: * "langPath" =>"Path to the language files", * "publicPath" =>" Path to the public / web directory", * "storagePath" => "Storage directory", * "resourcePath" =>"Resources directory", * "getCachedServicesPath" => "Path to the cached services.php", * "getCachedPackagesPath" => "Path to the cached packages.php", * "getCachedConfigPath" => "Path to the configuration cache", * "getCachedRoutesPath" => "Path to the routes cache", * "getCachedEventsPath" => "Path to the events cache file", * "getNamespace" => "Application namespace" ## 0.1.8 - 2020-06-18 ### Add :nail_care: Style output table via --style option. You can choose one of these styles (box-double is the default used by LaraLens): * default * borderless * compact * symfony-style-guide * box * box-double :eyeglasses: Runtime config: * environmentPath * environmentFile * environmentFilePath ### Change * Refactor for App::"function"() * update tests * update readme * update help (-h) ## 0.1.7 - 2020-06-16 ### Add Database connection: * connection name * getQueryGrammar * getDriverName * getDatabaseName * getTablePrefix * database server version Runtime configuration: * Laravel version * PHP version ## 0.1.6 - 2020-06-01 ### Add * Add show option --show (all|config|runtime|connection|database|migration) ## 0.1.5 - 2020-05-29 ### Improve * managing a better output * extracting long message from tables * settings width for columns tables ## 0.1.4 - 2020-05-28 ### Fix * Catch HTTP connection exception ## 0.1.3 - 2020-05-27 ### Add * detect DB connection type; * get tables for mysql; * get tables for sqlite; * count and retrieve last row from a table. Table and column name are as input parameters; * test database diagnostics; * update readme for documentation. ## 0.1.2 - 2020-05-22 ### Add * Add new argument as input (it is optional): - overview: you can see configuration, http connection, db connection etc.; - 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. ## 0.1.1 - 2020-05-22 ### Add * Add runtime config: * App::getLocale() * App::environment()) * Generated url via asset() and url() helpers * Invoke migrate:status ## 0.1.0 - 2020-05-21 * :tada: initial release * Add laralens:diagnostic artisan command (Laravel) * Check config parameter like app.url, app.locale, app.url and database.* * Check the http connection with "app.url" defined in base configuration * Check the connection with DB and counts the row for a specific table (users by default) ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing Contributions are **welcome** and will be fully **credited**. Please read and understand the contribution guide before creating an issue or pull request. ## Etiquette This project is open source, and as such, the maintainers give their free time to build and maintain the source code held within. They make the code freely available in the hope that it will be of use to other developers. It would be extremely unfair for them to suffer abuse or anger for their hard work. Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the world that developers are civilized and selfless people. It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 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. ## Viability When requesting or submitting new features, first consider whether it might be useful to others. Open source projects are used by many developers, who may have entirely different needs to your own. Think about whether or not your feature is likely to be used by other users of the project. ## Procedure Before filing an issue: - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. - Check to make sure your feature suggestion isn't already present within the project. - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. - Check the pull requests tab to ensure that the feature isn't already in progress. Before submitting a pull request: - Check the codebase to ensure that your feature doesn't already exist. - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. ## Open a Pull Request In order to maintain consistency in the source code we are following PSR12 coding standard, and using PHP stan for static code analysis. You can use the command: ``` make allcheck ``` to launch - **[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); - **PHPstan** with [level 5](https://phpstan.org/user-guide/rule-levels) - **PestPHP** to execute all tests from ./tests/* I suggest to launch *composer all* before to commit or before to create PR. 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. If you want to contribute with an high quality PR, I suggest you to focus not just on the source code but also: - **Add tests!** - Your patch won't be accepted if it doesn't have tests. - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. - **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. **Happy coding**! ================================================ FILE: LICENSE.md ================================================ MIT License Copyright (c) Roberto Butti Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # LaraLens ![CI/CD Github Actions](https://img.shields.io/github/actions/workflow/status/hi-folks/lara-lens/php-code-quality.yml?style=for-the-badge) ![GitHub last commit](https://img.shields.io/github/last-commit/hi-folks/lara-lens?style=for-the-badge) ![GitHub Release Date](https://img.shields.io/github/release-date/hi-folks/lara-lens?style=for-the-badge) ![Packagist PHP Version](https://img.shields.io/packagist/v/hi-folks/lara-lens?style=for-the-badge) ![LaraLens](https://raw.githubusercontent.com/Hi-Folks/lara-lens/develop/LaraLens-Laravel-Artisan.png) ## What **LaraLens** is a _Laravel_ artisan command to show you the current configuration of your application. It is useful to show in your terminal the status of: * some useful configuration variable; * the database connection; * the tables in the database; * the connection via HTTP request; * the server requirements (PHP version, PHP modules required and installed, Laravel version etc.). ![LaraLens - diagnostic package for Laravel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ryagpu0qqwgy476x5w5b.gif) ## Why 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. I tried to show more information in just one command. 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?". ## Installation You can install the package via composer: ```shell script composer require hi-folks/lara-lens ``` The Packagist page is: https://packagist.org/packages/hi-folks/lara-lens ## Usage ```shell script php artisan laralens:diagnostic ``` ### Usage: control database connection 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): ```shell script php artisan laralens:diagnostic --table=migrations --column-sort=id ``` To take the last **created** user: ```shell script php artisan laralens:diagnostic --table=users --column-sort=created_at ``` To take the last **updated** user: ```shell script php artisan laralens:diagnostic --table=users --column-sort=updated_at ``` ### Usage: control the output You can control the output via the _show_ option. You can define: * config * connection * database * runtime * migration * php-ext * php-ini * all The default for _--show_ option (if you avoid specifying _--show_) is to display: config, connection, database, runtime, migration. ```shell script php artisan laralens:diagnostic --show=config --show=connection --show=database --show=runtime --show=migration ``` If you want to see only database information: ```shell script php artisan laralens:diagnostic --show=database ``` If you want to see a verbose output (with also PHP extensions and PHP INI values): ```shell script php artisan laralens:diagnostic --show=all ``` or better: ```shell script php artisan laralens:diagnostic --all ``` If you want to see only PHP extensions: ```shell script php artisan laralens:diagnostic --show=php-ext ``` If you want to see only PHP INI values: ```shell script php artisan laralens:diagnostic --show=php-ini ``` ### Usage: skip database connection and database diagnostics If your Laravel application doesn't use the database, you can skip the database inspection with --skip-database option. ```shell script php artisan laralens:diagnostic --skip-database ``` ### Usage: show some oprating system information You can show some operating system information like: - PHP script owner's UID - Current User - Operating System - Hostname - Release name - Machine Name - Version info using _"--show os"_ option or _"--show all"_ option ```shell php artisan laralens:diagnostic --show os ``` ### Usage: change the style of output table You can choose one of these styles via *--style=* option: * default * borderless * compact * symfony-style-guide * box * box-double For example: ```sh php artisan laralens:diagnostic --style=borderless ``` ### Usage: change the width of the output table To use 120 characters (wide terminal), you can use --large option ```sh php artisan laralens:diagnostic --large ``` ### Testing ``` bash composer test ``` ### Changelog 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 Add `LARALENS_WEB_ENABLED=on` option to your .env file. You may also override the default parameters for `LARALENS_PREFIX` and `LARALENS_MIDDLEWARE` ``` # Wether Web Report should be enabled or not LARALENS_WEB_ENABLED=on # Path prefix in order to acess the Web Report via browser LARALENS_PREFIX="laralens" # Which middleware should be used when acessing the Web Report, separete more with ; LARALENS_MIDDLEWARE="web;auth.basic" ``` 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 ```php return [ 'prefix' => env('LARALENS_PREFIX', 'laralens'), // URL prefix (default=laralens) 'middleware' => explode(';', env('LARALENS_MIDDLEWARE', 'web')), // middleware (default=web) more separate with ; 'web-enabled' => env('LARALENS_WEB_ENABLED', 'off') // 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 to remove LARALENS_WEB_ENABLED config from .env file or set it to _off_ ``` LARALENS_WEB_ENABLED=off ``` ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ### Submit ideas or feature requests or issues * 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) * 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) ## Credits - [Roberto Butti](https://github.com/hi-folks) - [All Contributors](https://github.com/Hi-Folks/lara-lens/graphs/contributors) - [Laravel Package Boilerplate](https://laravelpackageboilerplate.com) ## Who talks about LaraLens - [Laravel News](https://laravel-news.com/inspect-application-configuration-with-laralens) - [Medium Article](https://levelup.gitconnected.com/laralens-a-laravel-command-for-inspecting-configuration-2bbb4e714cf7) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. ================================================ FILE: composer.json ================================================ { "name": "hi-folks/lara-lens", "description": "Laravel Diagnostic command for configuration, db connection, http request", "keywords": [ "laravel", "diagnostic", "cli", "package", "command-line", "console", "hi-folks", "lara-lens" ], "homepage": "https://github.com/hi-folks/lara-lens", "license": "MIT", "type": "library", "authors": [ { "name": "Roberto Butti", "role": "Developer" } ], "require": { "php": "^8.0|^8.1|^8.2|^8.3|^8.4", "ext-json": "*", "guzzlehttp/guzzle": "^7.8", "nunomaduro/termwind": "^1.15|^2.0" }, "require-dev": { "doctrine/dbal": "^3.0|^4.0", "larastan/larastan": "^2.0", "laravel/pint": "^1.4", "orchestra/testbench": "^7.0|^8.0|^9.0", "pestphp/pest": "^2.34", "pestphp/pest-plugin-laravel": "^1.2|^2.3", "phpunit/phpunit": "^10.5", "rector/rector": "^0.14|^1.0" }, "autoload": { "psr-4": { "HiFolks\\LaraLens\\": "src" } }, "autoload-dev": { "psr-4": { "HiFolks\\LaraLens\\Tests\\": "tests" } }, "scripts": { "all": [ "@style-fix", "@phpstan", "@test" ], "style-fix": "pint", "style-check": "pint --test", "phpstan": "phpstan analyse -c ./phpstan.neon --no-progress", "test": "./vendor/bin/pest --order-by random", "rector": "rector process --dry-run" }, "scripts-descriptions": { "test": "Run all tests, via PespPHP", "style-fix": "Fix the code style with PSR12", "style-check": "Check the code style with PSR12", "phpstan": "Run static code analysis via PHPStan", "rector": "Suggest refactoring to be more PHP 8 compliant", "all": "Execute tasks for fixing code style, static code analysis and tests" }, "config": { "sort-packages": true, "allow-plugins": { "composer/package-versions-deprecated": false, "pestphp/pest-plugin": true } }, "extra": { "laravel": { "providers": [ "HiFolks\\LaraLens\\LaraLensServiceProvider" ], "aliases": { "LaraLens": "HiFolks\\LaraLens\\LaraLensFacade" } } } } ================================================ FILE: config/config.php ================================================ env('LARALENS_PREFIX', 'laralens'), // URL prefix (default=laralens) 'middleware' => explode(';', env('LARALENS_MIDDLEWARE', 'web')), // middleware (default=web) more separate with ; 'web-enabled' => env('LARALENS_WEB_ENABLED', 'off') // Activate web view (default=off) ]; ================================================ FILE: phpcs.xml ================================================ PHPCS configuration file. src */exclude/* ================================================ FILE: phpstan.neon ================================================ includes: - ./vendor/larastan/larastan/extension.neon parameters: reportUnmatchedIgnoredErrors: false ignoreErrors: - '#Parameter .1 \$separator of function explode expects non-empty-string, string given.#' level: 5 paths: - src ================================================ FILE: phpunit.xml.dist ================================================ tests src/ ================================================ FILE: phpunit.xml.dist.bak ================================================ src/ tests ================================================ FILE: pint.json ================================================ { "preset": "psr12" } ================================================ FILE: psalm.xml ================================================ ================================================ FILE: rector.php ================================================ paths([ __DIR__ . '/src' ]); // register a single rule // $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); // define sets of rules $rectorConfig->sets([ LevelSetList::UP_TO_PHP_80 ]); }; ================================================ FILE: resources/views/laralens/index.blade.php ================================================ 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 ================================================ FILE: resources/views/laralens/term/checks.blade.php ================================================
@if (sizeof($rows) > 0)
CHECK: issues found
@else
CHECK: everything looks good
@endif
@foreach ($rows as $row) @php $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); $label = Arr::get($row, "label", ""); @endphp @if ($label === "*** HINT")
💡 Hint: {{ Arr::get($row, "value", "") }}
@else
$lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR, 'bg-yellow text-black' => $lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING, 'bg-green text-white' => $lineType !== HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR && $lineType !== HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING, ])> {{ Arr::get($row, "label", "")}}
@if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) {{ Arr::get($row, "value", "")}} @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) {{ Arr::get($row, "value", "")}} @else {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} @endif
@endif @endforeach
================================================ FILE: resources/views/laralens/term/table.blade.php ================================================
{{ $title }}
@foreach ($rows as $row) @php $lineType = Arr::get($row, "lineType", HiFolks\LaraLens\ResultLens::LINE_TYPE_DEFAULT); $label = Arr::get($row, "label", ""); @endphp @if ($label === "*** HINT")
Hint:
{{ Arr::get($row, "value", "") }}
@else
{{ Arr::get($row, "label", "")}} @if ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_ERROR) {{ Arr::get($row, "value", "")}} @elseif ($lineType === HiFolks\LaraLens\ResultLens::LINE_TYPE_WARNING) {{ Arr::get($row, "value", "")}} @else {{ Str::replace("\\", "/", Arr::get($row, "value", "")) }} @endif
@endif @endforeach
================================================ FILE: routes/web.php ================================================ name('laralens.index'); ================================================ FILE: src/Console/LaraLensCommand.php ================================================ info(json_encode(config()->all(), JSON_PRETTY_PRINT)); } private function overview($checkTable = "users", $columnSorting = "created_at", $show = self::OPTION_SHOW_ALL): void { $ll = new LaraLens(); if ($show & self::OPTION_SHOW_CONFIGS) { $output = $ll->getConfigs(); $this->printOutputTerm("Config keys via config()", $output->toArray()); } if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { $output = $ll->getRuntimeConfigs(); $this->printOutputTerm("Runtime Configs", $output->toArray()); $output = $ll->checkServerRequirements(); $this->printOutputTerm("Laravel Requirements", $output->toArray()); } if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) { $output = $ll->checkFiles(); $this->printOutputTerm("Check files", $output->toArray()); } if ($show & self::OPTION_SHOW_CONNECTIONS) { $output = $ll->getConnections($this->urlPath); $this->printOutputTerm("Connections", $output->toArray()); } if ($show & self::OPTION_SHOW_DATABASE) { $output = $ll->getDatabase($checkTable, $columnSorting); $this->printOutputTerm("Database", $output->toArray()); } if ($show & self::OPTION_SHOW_MIGRATION) { try { $this->call('migrate:status'); } catch (\Exception $e) { $r = new ResultLens(); $r->add( "Check migrate status", "Error in check migration" ); $ll->checksBag->addErrorAndHint( "Migration status", $e->getMessage(), "Check the Database configuration" ); $this->printOutputTerm("Migration", $r->toArray()); } } if ($show & self::OPTION_SHOW_PHPEXTENSIONS) { $output = $ll->getPhpExtensions(); $this->printOutputTerm("PHP Extensions", $output->toArray()); } if ($show & self::OPTION_SHOW_PHPINIVALUES) { $output = $ll->getPhpIniValues(); $this->printOutputTerm("PHP ini config", $output->toArray()); } if ($show & self::OPTION_SHOW_OS) { $output = $ll->getOsConfigs(); $this->printOutputTerm("Operating System", $output->toArray()); } $this->printChecksTerm($ll->checksBag->toArray()); } public function handle(): void { $op = $this->argument("op"); $checkTable = $this->option("table"); $styleTable = $this->option("style"); $show = self::OPTION_SHOW_DEFAULT; if (in_array($styleTable, explode("|", self::TABLE_STYLES))) { $this->styleTable = $styleTable; } else { $this->styleTable = self::DEFAULT_STYLE; } $columnSorting = $this->option("column-sort"); $showOptions = $this->option("all") ? ['all'] : $this->option("show"); if (is_array($showOptions)) { if (count($showOptions) > 0) { $show = self::OPTION_SHOW_NONE; if (in_array("all", $showOptions)) { $show = self::OPTION_SHOW_ALL; } else { $show = (in_array("config", $showOptions)) ? $show | self::OPTION_SHOW_CONFIGS : $show ; $show = (in_array("runtime", $showOptions)) ? $show | self::OPTION_SHOW_RUNTIMECONFIGS : $show ; $show = (in_array("connection", $showOptions)) ? $show | self::OPTION_SHOW_CONNECTIONS : $show ; $show = (in_array("database", $showOptions)) ? $show | self::OPTION_SHOW_DATABASE : $show ; $show = (in_array("migration", $showOptions)) ? $show | self::OPTION_SHOW_MIGRATION : $show ; $show = (in_array("php-ext", $showOptions)) ? $show | self::OPTION_SHOW_PHPEXTENSIONS : $show ; $show = (in_array("php-ini", $showOptions)) ? $show | self::OPTION_SHOW_PHPINIVALUES : $show ; $show = (in_array("os", $showOptions)) ? $show | self::OPTION_SHOW_OS : $show ; } } else { $show = self::OPTION_SHOW_DEFAULT; } } $skipDatabases = $this->option("skip-database"); if ($skipDatabases) { $show = $show - self::OPTION_SHOW_DATABASE - self::OPTION_SHOW_MIGRATION; } $this->widthLabel = $this->option("width-label"); $this->widthValue = $this->option("width-value"); if ($this->option("large")) { $this->widthValue = self::DEFAULT_LARGE_WIDTH; } $this->urlPath = $this->option("url-path"); if (is_null($this->urlPath)) { $this->urlPath = self::DEFAULT_PATH; } $version = \Composer\InstalledVersions::getPrettyVersion('hi-folks/lara-lens'); $this->title("Laralens (" . $version . ")"); match ($op) { 'overview' => $this->overview($checkTable, $columnSorting, $show), 'allconfigs' => $this->allConfigs(), default => $this->info("What you mean? try with 'php artisan laralens:diagnostic --help'"), }; } } ================================================ FILE: src/Http/Controllers/Controller.php ================================================ '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" => "PHP Extensions", "description" => "List of PHP extensions loaded", "data" => $ll->getPhpExtensions()->toArray() ], [ "title" => "PHP INI", "description" => "List of php ini values", "data" => $ll->getPhpIniValues()->toArray() ], [ "title" => "Credits", "description" => "LaraLens app", "data" => $ll->getCredits()->toArray() ], ]; $checks = $ll->checksBag->toArray(); return view('lara-lens::laralens.index', ['data' => $data, 'checks' => $checks]); } } ================================================ FILE: src/LaraLensFacade.php ================================================ loadTranslationsFrom(__DIR__.'/../resources/lang', 'lara-lens'); $this->loadViewsFrom(__DIR__ . '/../resources/views', 'lara-lens'); // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); //$this->loadRoutesFrom(__DIR__.'/routes.php'); $this->registerRoutes(); if ($this->app->runningInConsole()) { $this->publishes( [ __DIR__ . '/../config/config.php' => config_path('lara-lens.php'), ], 'config' ); // Publishing the views. /*$this->publishes([ __DIR__.'/../resources/views' => resource_path('views/vendor/lara-lens'), ], 'views');*/ // Publishing assets. /*$this->publishes([ __DIR__.'/../resources/assets' => public_path('vendor/lara-lens'), ], 'assets');*/ // Publishing the translation files. /*$this->publishes([ __DIR__.'/../resources/lang' => resource_path('lang/vendor/lara-lens'), ], 'lang');*/ // Registering package commands. $this->commands( [ LaraLensCommand::class, ] ); } } protected function registerRoutes(): void { Route::group($this->routeConfiguration(), function () { $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); }); } /** * @return (\Illuminate\Config\Repository|mixed)[] * * @psalm-return array{prefix: \Illuminate\Config\Repository|mixed, middleware: \Illuminate\Config\Repository|mixed} */ protected function routeConfiguration(): array { return [ 'prefix' => config('lara-lens.prefix', 'laralens-diagnostic'), 'middleware' => config('lara-lens.middleware'), ]; } /** * Register the application services. */ public function register() { // Automatically apply the package configuration $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'lara-lens'); // Register the main class to use with the facade $this->app->singleton( 'lara-lens', fn () => new LaraLens() ); } } ================================================ FILE: src/Lens/LaraHttp.php ================================================ get($url, ['timeout' => 1])); } catch (GuzzleException $e) { $response = null; throw $e; } return $response; } } ================================================ FILE: src/Lens/LaraLens.php ================================================ checksBag = new ResultLens(); } /** * @return ResultLens */ public function getCredits() { $results = new ResultLens(); $results->add( "App", "powered by LaraLens" ); return $results; } /** * @return string */ public static function printBool(bool $b) { return $b ? "Yes" : "No"; } } ================================================ FILE: src/Lens/Objects/LaraHttpResponse.php ================================================ response->getStatusCode(); } /** * Return true if the status code of the HTTP response is an error * * @return bool */ public function failed() { return ($this->response->getStatusCode() >= 400); } } ================================================ FILE: src/Lens/Traits/BaseTraits.php ================================================ 3) { if (Str::startsWith($value, $curDir)) { $value = "." . Str::after($value, $curDir); } } return $value; } } ================================================ FILE: src/Lens/Traits/ConfigLens.php ================================================ $value) { $results->add( ".env " . $value, env($value) ); } return $results; } public function checkDebugEnv(ResultLens|null $results = null): \HiFolks\LaraLens\ResultLens { if (is_null($results)) { $results = new ResultLens(); } $debug = config("app.debug"); $env = config("app.env"); $results->add( "ENV", $env ); $results->add( "DEBUG", $debug ); if ($debug && $env === "production") { $this->checksBag->addWarningAndHint( "Check config ENV and DEBUG", "You have DEBUG mode in Production.", "Change you APP_DEBUG env parameter to false for Production environments" ); } return $results; } public function getConfigsDatabase(ResultLens|null $results = null): \HiFolks\LaraLens\ResultLens { if (is_null($results)) { $results = new ResultLens(); } $configKeys = [ "database.default", "database.connections." . config("database.default") . ".driver", "database.connections." . config("database.default") . ".url", "database.connections." . config("database.default") . ".host", "database.connections." . config("database.default") . ".port", "database.connections." . config("database.default") . ".username", "database.connections." . config("database.default") . ".database" ]; foreach ($configKeys as $key => $value) { $results->add( "" . $value, config($value) ); } return $results; } public function getConfigs() { $results = new ResultLens(); $results->add( "Running diagnostic", date('Y-m-d H:i:s') ); $configKeys = [ "app.timezone", "app.locale", "app.name", "app.url", ]; foreach ($configKeys as $key => $value) { $results->add( "" . $value, config($value) ); } $results = $this->checkDebugEnv($results); $results = $this->getConfigsDatabase($results); return $results; } } ================================================ FILE: src/Lens/Traits/DatabaseLens.php ================================================ $value) { $stringTables = $stringTables . $value . ";"; } } return $stringTables; } public function getTablesListSqlite(): string { $tables = DB::table('sqlite_master') ->select('name') ->where('type', 'table') ->orderBy('name') ->pluck('name')->toArray(); $stringTables = implode(",", $tables); return $stringTables; } /** * Try to establish a db connection. * If it fails, return FALSE and fill checksBag. */ public function dbConnection(): false|\Illuminate\Database\Connection { $dbconnection = false; try { $dbconnection = DB::connection(); } catch (\Exception $e) { $dbconnection = false; $this->checksBag->addErrorAndHint( "Error Database connection", "- " . $e->getCode() . " - " . $e->getMessage(), "Check out your .env file for these parameters: DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD" ); } return $dbconnection; } public function getDatabaseConnectionInfos( Connection $dbConnection, ResultLens $results, $checkTable, $columnSorting ) { $connectionName = $dbConnection->getName(); $results->add( "Connection name", $connectionName ); $grammar = $dbConnection->getQueryGrammar(); $results->add( "Query Grammar", Str::afterLast($grammar::class, '\\') ); $driverName = $dbConnection->getDriverName(); $results->add( "Driver name", $driverName ); $databaseName = $dbConnection->getDatabaseName(); $results->add( "Database name", $databaseName ); $tablePrefix = $dbConnection->getTablePrefix(); $results->add( "Table prefix", $tablePrefix ); $pdo = null; $pdoIsOk = false; try { $pdo = $dbConnection->getPDO(); $pdoIsOk = true; } catch (\PDOException $e) { $this->checksBag->addWarningAndHint( "Access to PDO (database)", $e->getMessage(), "Check .env DB_*" ); } if (!$pdoIsOk) { if ($driverName === "mongodb") { $this->checksBag->addInfoAndHint( "Connection and PDO driver", "It is ok! Because you are using " . $driverName . ", and it doesn't support PDO driver.", "" ); } else { } } else { try { $serverVersion = $dbConnection->getPDO()->getAttribute(\PDO::ATTR_SERVER_VERSION); $results->add( "Server version", $serverVersion ); } catch (\PDOException $e) { $results->addErrorAndHint( "Error DB", $e->getMessage(), "Check out your .env file for these parameters: DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD" ); $results = $this->getConfigsDatabase($results); $results = $this->getConfigsDatabaseFromEnv($results); return $results; } $connectionType = $dbConnection->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME); $results->add( "Database connection type", $connectionType ); $stringTables = ""; $stringTables = match ($connectionType) { 'mysql' => $this->getTablesListMysql(), 'sqlite' => $this->getTablesListSqlite(), default => "<>", }; $results->add( "Tables", $stringTables ); $checkCountMessage = ""; $checkCount = 0; try { $checkCount = DB::table($checkTable) ->select(DB::raw('*')) ->count(); } catch (\Exception) { $checkCount = 0; $checkCountMessage = " - error with " . $checkTable . " table"; $results->addErrorAndHint( "Table Error", "Failed query, table <" . $checkTable . "> ", "Make sure that table <" . $checkTable . "> exists, available tables : " . (($stringTables == "") ? "Not tables found" : $stringTables) ); } $results->add( "Query Table", $checkTable ); $results->add( "Number of rows", $checkCount . $checkCountMessage ); if ($checkCount > 0) { try { $latest = DB::table($checkTable)->latest($columnSorting)->first(); $results->add( "LAST row in table", json_encode($latest, JSON_THROW_ON_ERROR) ); } catch (QueryException) { $results->addErrorAndHint( "Table Error", "Failed query, table <" . $checkTable . "> column <" . $columnSorting . ">", "Make sure that table <" . $checkTable . "> column <" . $columnSorting . "> exists" ); } } } } public function getDatabase($checkTable = "users", $columnSorting = "created_at"): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); $dbConnection = $this->dbConnection(); $results->add( "Database default", config("database.default") ); if ($dbConnection) { $this->getDatabaseConnectionInfos($dbConnection, $results, $checkTable, $columnSorting); } return $results; } } ================================================ FILE: src/Lens/Traits/FilesystemLens.php ================================================ storage_path('app/public')]; //return $this->laravel['config']['filesystems.links'] ?? } public function checkFiles(): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); $envExists = file_exists(App::environmentFilePath()); if ($envExists) { $results->add( "Check .env exists", self::printBool($envExists) ); } else { $results->addWarningAndHint( "Check .env exists", ".env not exists", "Create .env file" ); } $results->add( "Check Languages directory", self::printBool(is_dir(App::langPath())) ); try { $langArray = scandir(App::langPath()); } catch (\Exception) { $langArray = false; } $languages = ""; if ($langArray) { $languages = implode(",", array_diff($langArray, ['..', '.', 'vendor'])); } else { $languages = "No language found"; $this->checksBag->addWarningAndHint( "List Languages directory", "No languages found in " . App::langPath(), "If your app needs translations, please fill " . App::langPath() . " or run `php artisan lang:publish`" ); } $results->add( "List Languages directory", $languages ); foreach ($this->links() as $link => $dir) { if (!file_exists($link)) { $this->checksBag->addWarningAndHint( "Check storage link", $this->stripPrefixDir($link) . " it doesn't exist.", "Check config/filesystem.php 'links' parameter, and execute 'php artisan storage:link'" ); } if (!file_exists($dir)) { $this->checksBag->addWarningAndHint( "Check storage target link", $this->stripPrefixDir($dir) . " it doesn't exist.", "Create directory target (for storage link) : " . $dir ); } $results->add( "Storage links:", "" ); $results->add( $this->stripPrefixDir($link), $this->stripPrefixDir($dir) ); } return $results; } } ================================================ FILE: src/Lens/Traits/HttpConnectionLens.php ================================================ add( "app.url configuration", $app_url ); $url = url($checkPath); $results->add( "url()->full()", url()->full() ); $results->add( "Connection HTTP URL", $url ); try { $response = LaraHttp::get($url); $results->add( "Connection HTTP Status", $response->status() ); if ($response->failed()) { $checkUrlHint = "Check APP_URL '" . $app_url . "' in .env file "; if ($checkPath !== "") { $checkUrlHint .= " or check this path: '" . $checkPath . "' in routing file (routes/web.php)"; } $this->checksBag->addWarningAndHint( "Connection HTTP Status", "Connection response not 20x, status code: " . $response->status() . " for " . $url, $checkUrlHint ); } } catch (\Exception $e) { $results->add( "Connection HTTP Status", "Error connection" ); $this->checksBag->addErrorAndHint( "Connection HTTP Status", "Connection Error: " . $e->getMessage(), "Check this URL: " . $app_url . " in .env file APP_URL" ); } return $results; } } ================================================ FILE: src/Lens/Traits/OperatingSystemLens.php ================================================ "Operating System", "n" => "Hostname", "r" => "Release name", "v" => "Version info", "m" => "Machine Name", "a" => "Full infos" ]; foreach ($modes as $key => $title) { $results->add( $title, php_uname($key) ); } } public function getOsConfigs(): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); $results->add( "PHP script owner's UID", getmyuid() ); $results->add( "Current User", get_current_user() ); $this->getUnameValues($results); return $results; } } ================================================ FILE: src/Lens/Traits/RuntimeLens.php ================================================ $label) { $value = call_user_func("App::" . $function); if (Str::length($curDir) > 3) { if (Str::startsWith($value, $curDir)) { $value = "." . Str::after($value, $curDir); } } $results->add( $label, $value ); } } private function getIniValues($results): void { $labels = [ "post_max_size", "upload_max_filesize", ]; foreach ($labels as $label) { $results->add( $label, ini_get($label) ); } } public function getRuntimeConfigs(): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); $results->add( "PHP Version", phpversion() ); $this->getIniValues($results); $results->add( "Current Directory", getcwd() ); $this->appCaller( $results, [ "version" => "Laravel Version", "getLocale" => "Locale", "getNamespace" => "Application namespace", "environment" => "Environment", "environmentPath" => "Environment file directory", "environmentFile" => "Environment file used", "environmentFilePath" => "Full path to the environment file", "langPath" => "Path to the language files", "publicPath" => "Path to the public / web directory", "storagePath" => "Storage directory", "resourcePath" => "Resources directory", "getCachedServicesPath" => "Path to the cached services.php", "getCachedPackagesPath" => "Path to the cached packages.php", "getCachedConfigPath" => "Path to the configuration cache", "getCachedRoutesPath" => "Path to the routes cache", "getCachedEventsPath" => "Path to the events cache file" ] ); $results->add( "Generated url for / ", url("/") ); $results->add( "Generated asset url for /test.js ", asset("/test.js") ); return $results; } public function checkServerRequirements(): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); $phpVersion = phpversion(); $laravelVersion = app()->version(); $laravelMajorVersion = Arr::get(explode('.', $laravelVersion), 0, "8"); $phpExtensionRequirements = [ "6" => [ "phpversion" => "7.2.0", "extensions" => [ "bcmath", "ctype", "fileinfo", "json", "mbstring", "openssl", "pdo", "tokenizer", "xml" ] ], "7" => [ "phpversion" => "7.2.5", "extensions" => [ "bcmath", "ctype", "fileinfo", "json", "mbstring", "openssl", "pdo", "tokenizer", "xml" ] ], "8" => [ "phpversion" => "7.3.0", "extensions" => [ "bcmath", "ctype", "fileinfo", "json", "mbstring", "openssl", "pdo", "tokenizer", "xml" ] ], "9" => [ "phpversion" => "8.0.2", "extensions" => [ "bcmath", "ctype", "fileinfo", "json", "mbstring", "openssl", "pdo", "tokenizer", "xml" ] ], "10" => [ "phpversion" => "8.1.0", "extensions" => [ "bcmath", "ctype", "curl", "dom", "fileinfo", "json", "mbstring", "openssl", "pcre", "pdo", "tokenizer", "xml" ] ], "11" => [ "phpversion" => "8.2.0", "extensions" => [ "ctype", "curl", "dom", "fileinfo", "filter", "json", "libxml", "mbstring", "openssl", "pcre", "phar", "reflection", "simplexml", "spl", "tokenizer", "xml", "xmlwriter" ] ] ]; if (!key_exists($laravelMajorVersion, $phpExtensionRequirements)) { $laravelMajorVersion = "11"; } $phpVersionRequired = $phpExtensionRequirements[$laravelMajorVersion]["phpversion"]; $results->add( "Laravel version", $laravelVersion . " ( " . $laravelMajorVersion . " )" ); $results->add( "PHP version", $phpVersion ); $results->add( "PHP version required (min)", $phpVersionRequired ); $helpInstall = [ "bcmath" => "BCMath Arbitrary Precision Mathematics: https://www.php.net/manual/en/bc.setup.php", "ctype" => "Character type checking: https://www.php.net/manual/en/book.ctype", "curl" => "Client URL Library: https://www.php.net/manual/en/book.curl.php", "dom" => "Document Object Model: https://www.php.net/manual/en/book.dom.php", "fileinfo" => "File Information: https://www.php.net/manual/en/book.fileinfo", "filter" => "Data Filtering: https://www.php.net/manual/en/book.filter.php", "json" => "JavaScript Object Notation: https://www.php.net/manual/en/book.json", "libxml" => "libxml: https://www.php.net/manual/en/book.libxml.php", "mbstring" => "Multibyte string: https://www.php.net/manual/en/book.mbstring.php", "openssl" => "OpenSSL: https://www.php.net/manual/en/book.openssl.php", "pcre" => "Regular Expressions (Perl-Compatible): https://www.php.net/manual/en/book.pcre.php", "pdo" => "PHP Data Objects: https://www.php.net/manual/en/book.pdo.php", "phar" => "Phar: https://www.php.net/manual/en/book.phar.php", "reflection" => "Reflection: https://www.php.net/manual/en/book.reflection.php", "simplexml" => "SimpleXML: https://www.php.net/manual/en/book.simplexml.php", "spl" => "Standard PHP Library (SPL): https://www.php.net/manual/en/book.spl.php", "tokenizer" => "Tokenizer: https://www.php.net/manual/en/book.tokenizer.php", "xml" => "XML Parser: https://www.php.net/manual/en/book.xml.php", "xmlwriter" => "XMLWriter: https://www.php.net/manual/en/book.xmlwriter.php" ]; $modulesOk = []; $modulesNotok = []; foreach ($phpExtensionRequirements[$laravelMajorVersion]["extensions"] as $p) { if (extension_loaded($p)) { $modulesOk[] = $p; } else { $modulesNotok[] = $p; } } //*** CHECK PHP VERSION if (version_compare($phpVersion, $phpVersionRequired) < 0) { $this->checksBag->addWarningAndHint( "PHP (" . $phpVersion . ") version check", "PHP version required: " . $phpVersionRequired . ", you have: " . $phpVersion, "You need to install PHP version: " . $phpVersionRequired ); } $results->add( "PHP (" . $phpVersion . ") version check", "PHP version required: " . $phpVersionRequired . ", you have: " . $phpVersion ); $results->add( "PHP extensions installed", implode(",", $modulesOk) ); if (count($modulesNotok) > 0) { $stringHint = "Please install these modules :" . PHP_EOL; foreach ($modulesNotok as $pko) { if (key_exists($pko, $helpInstall)) { $stringHint = $pko . " : " . $helpInstall[$pko] . PHP_EOL; } else { $stringHint = $pko . PHP_EOL; } } $this->checksBag->addWarningAndHint( "PHP extensions missing", "Some PHP Extensions are missing", $stringHint ); } else { $results->add( "PHP extension installed", "Looks good for Laravel " . $laravelMajorVersion ); } return $results; } public function getPhpExtensions(): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); foreach (get_loaded_extensions() as $name) { $results->add( $name, "" ); } return $results; } public function getPhpIniValues(): \HiFolks\LaraLens\ResultLens { $results = new ResultLens(); foreach (ini_get_all() as $name => $row) { $results->add( $name, $row['local_value'] ); } return $results; } } ================================================ FILE: src/Lens/Traits/TermOutput.php ================================================ $title, 'rows' => $rows ]) ); } public function printChecksTerm(array $rows): void { render( view('lara-lens::laralens.term.checks', [ 'rows' => $rows ]) ); } public function title(string $title): void { render("
$title
"); } } ================================================ FILE: src/ResultLens.php ================================================ reset(); } public function reset(): void { $this->result = collect(); $this->idx = -1; } public function addError($label, $value): void { $this->add($label, $value, true, self::LINE_TYPE_ERROR); } public function addWarning($label, $value): void { $this->add($label, $value, true, self::LINE_TYPE_WARNING); } public function addInfo($label, $value): void { $this->add($label, $value, true, self::LINE_TYPE_INFO); } public function addHint($value): void { $this->add("*** HINT", $value, true, self::LINE_TYPE_HINT); } public function addErrorAndHint($label, $errorMessage, $hintMessage): void { $this->addError($label, $errorMessage); $this->addHint($hintMessage); } public function addWarningAndHint($label, $warningMessage, $hintMessage): void { $this->addWarning($label, $warningMessage); $this->addHint($hintMessage); } public function addInfoAndHint($label, $infoMessage, $hintMessage): void { $this->addInfo($label, $infoMessage); $this->addHint($hintMessage); } public function add($label, $value, $forceLine = false, $lineType = self::LINE_TYPE_DEFAULT): void { $this->result->push( [ "label" => $label, "value" => $value, "isLine" => $forceLine, "lineType" => $lineType ] ); $this->idx++; } /** * @return bool */ public static function isMessageLine(string $lineType) { return (($lineType === self::LINE_TYPE_ERROR) || ($lineType === self::LINE_TYPE_WARNING) || ($lineType === self::LINE_TYPE_INFO)); } public static function isHintLine($lineType): bool { return ($lineType === self::LINE_TYPE_HINT); } public function toArray() { return $this->result->toArray(); } } ================================================ FILE: tests/Feature/ConsistencyTest.php ================================================ getConfigs() ->toArray() ->toBeArray() ->toHaveCount(14) ->checksBag->toArray() ->toBeArray() ->toBeEmpty(); //test check config length 0 config(['app.debug' => true]); config(['app.env' => "production"]); expect(laralens())->getConfigs() ->toArray() ->toBeArray() ->toHaveCount(14) ->checksBag->toArray() ->toBeArray() ->toHaveCount(2); // 2 = 1 for the warning , 1 for the hint }); it('can retrieve runtimeconfig as array of 22 items') ->expect(fn () => laralens()) ->getRuntimeConfigs()->toArray() ->toBeArray() ->toHaveCount(22); it('can retrieve databases as array with 8-13 items') ->expect(fn () => laralens()) ->getDatabase()->toArray() ->toBeArray() ->toHaveCountBetween(8, 13); test('facade', function () { $this->assertIsObject($this->app["lara-lens"], "Test object facade"); }); test('Credits returned as non-empty array') ->expect(fn () => laralens()) ->getCredits()->toArray() ->toBeArray() ->not()->toBeEmpty(); it('can retrieve PHP extensions as array') ->expect(fn () => laralens()) ->getPhpExtensions()->toArray() ->toBeArray() ->not()->toBeEmpty(); it('can retrieve PHP ini as array') ->expect(fn () => laralens()) ->getPhpIniValues()->toArray() ->toBeArray() ->not()->toBeEmpty(); it('can retrieve OS config as array') ->expect(fn () => laralens()) ->getOsConfigs()->toArray() ->toBeArray() ->toHaveCountBetween(0, 8); test('connection_array', function () { Http::fake(); expect(fn () => laralens()) ->getConnections()->toArray() ->toBeArray() ->toHaveCount(3); })->skip(); ================================================ FILE: tests/Pest.php ================================================ in('Feature'); /* |-------------------------------------------------------------------------- | Expectations |-------------------------------------------------------------------------- | | When you're writing tests, you often need to check that values meet certain conditions. The | "expect()" function gives you access to a set of "expectations" methods that you can use | to assert different things. Of course, you may extend the Expectation API at any time. | */ expect()->extend('toHaveCountBetween', function (int $min, int $max) { expect(count($this->value))->toBeGreaterThanOrEqual($min) ->toBeLessThanOrEqual($max); return $this; }); /* |-------------------------------------------------------------------------- | Functions |-------------------------------------------------------------------------- | | While Pest is very powerful out-of-the-box, you may have some testing code specific to your | project that you don't want to repeat in every file. Here you can also expose helpers as | global functions to help you to reduce the number of lines of code in your test files. | */ /** * Returns a new instance of Laralens * * @return LaraLens */ function laralens(): LaraLens { return new LaraLens(); } ================================================ FILE: tests/TestCase.php ================================================