diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 42617ac8..beeb2fc1 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -21,7 +21,7 @@ checks: tools: external_code_coverage: timeout: 600 - runs: 3 + runs: 2 php_code_sniffer: enabled: true config: diff --git a/.travis.yml b/.travis.yml index 083fec75..d407e33d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ language: php sudo: false php: - - 7.1.3 - - 7.1 - 7.2 - 7.3 - nightly @@ -23,5 +21,5 @@ script: - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover after_script: - - if [ "$TRAVIS_PHP_VERSION" != "7.3" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$TRAVIS_PHP_VERSION" != "7.3" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi + - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi + - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/README.md b/README.md index fc89ab8e..864a6ded 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/LogViewer/rel ## Features - A great Log viewer API. - - Laravel `5.0` to `5.8` are supported. + - Laravel `5.x` & `6.0` are supported. - Ready to use (Views, Routes, controllers … Out of the box) [Note: No need to publish assets] - View, paginate, filter, download and delete logs. - Load a custom logs storage path. @@ -93,7 +93,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail. ![Logs list](https://raw.githubusercontent.com/ARCANEDEV/LogViewer/master/_screenshots/2-logs-list.jpg) ![Single log](https://raw.githubusercontent.com/ARCANEDEV/LogViewer/master/_screenshots/3-single-log.jpg) -[badge_laravel]: https://img.shields.io/badge/Laravel-5.x-orange.svg?style=flat-square +[badge_laravel]: https://img.shields.io/badge/Laravel-5.x%20to%206.0-orange.svg?style=flat-square [badge_license]: https://img.shields.io/packagist/l/arcanedev/log-viewer.svg?style=flat-square [badge_build]: https://img.shields.io/travis/ARCANEDEV/LogViewer.svg?style=flat-square [badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/LogViewer.svg?style=flat-square diff --git a/_docs/0.Home.md b/_docs/0.Home.md index f964661e..9d31dba0 100644 --- a/_docs/0.Home.md +++ b/_docs/0.Home.md @@ -5,7 +5,7 @@ This package allows you to keep track of each one of your logs stored under `sto ## Features - A great Log viewer API. - - Laravel `5.0` to `5.8` are supported. + - Laravel `5.x` & `6.0` are supported. - Ready to use (Views, Routes, controllers … Out of the box) [Note: No need to publish assets] - View, paginate, filter, download and delete logs. - Load a custom logs storage path. diff --git a/_docs/1.Installation-and-Setup.md b/_docs/1.Installation-and-Setup.md index 9f2f4ed4..bb968cae 100644 --- a/_docs/1.Installation-and-Setup.md +++ b/_docs/1.Installation-and-Setup.md @@ -29,6 +29,7 @@ Laravel uses the [Monolog PHP logging library](https://github.com/Seldaek/monolo | ![LogViewer v4.5.x][log_viewer_4_5_x] | ![Laravel v5.6][laravel_5_6] | | ![LogViewer v4.6.x][log_viewer_4_6_x] | ![Laravel v5.7][laravel_5_7] | | ![LogViewer v4.7.x][log_viewer_4_7_x] | ![Laravel v5.8][laravel_5_8] | +| ![LogViewer v5.0.x][log_viewer_5_0_x] | ![Laravel v6.0][laravel_6_0] | [laravel_5_0]: https://img.shields.io/badge/v5.0-supported-brightgreen.svg?style=flat-square "Laravel v5.0" [laravel_5_1]: https://img.shields.io/badge/v5.1-supported-brightgreen.svg?style=flat-square "Laravel v5.1" @@ -39,6 +40,7 @@ Laravel uses the [Monolog PHP logging library](https://github.com/Seldaek/monolo [laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6" [laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7" [laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8" +[laravel_6_0]: https://img.shields.io/badge/v6.0-supported-brightgreen.svg?style=flat-square "Laravel v6.0" [log_viewer_4_2_x]: https://img.shields.io/badge/version-4.2.*-blue.svg?style=flat-square "LogViewer v4.2.*" [log_viewer_4_3_x]: https://img.shields.io/badge/version-4.3.*-blue.svg?style=flat-square "LogViewer v4.3.*" @@ -46,6 +48,7 @@ Laravel uses the [Monolog PHP logging library](https://github.com/Seldaek/monolo [log_viewer_4_5_x]: https://img.shields.io/badge/version-4.5.*-blue.svg?style=flat-square "LogViewer v4.5.*" [log_viewer_4_6_x]: https://img.shields.io/badge/version-4.6.*-blue.svg?style=flat-square "LogViewer v4.6.*" [log_viewer_4_7_x]: https://img.shields.io/badge/version-4.7.*-blue.svg?style=flat-square "LogViewer v4.7.*" +[log_viewer_5_0_x]: https://img.shields.io/badge/version-5.0.*-blue.svg?style=flat-square "LogViewer v5.0.*" ## Composer diff --git a/composer.json b/composer.json index 2bd488e4..92e42121 100644 --- a/composer.json +++ b/composer.json @@ -14,15 +14,16 @@ "type": "library", "license": "MIT", "require": { - "php": ">=7.1.3", + "php": ">=7.2.0", + "ext-json": "*", "psr/log": "~1.0", - "arcanedev/support": "~4.5.0" + "arcanedev/support": "~5.0.0" }, "require-dev": { - "orchestra/testbench": "~3.8.0", + "orchestra/testbench": "~4.0.0", "mockery/mockery": "~1.0", - "phpunit/phpcov": "~5.0|~6.0", - "phpunit/phpunit": "~7.0|~8.0" + "phpunit/phpcov": "~6.0", + "phpunit/phpunit": "~8.0" }, "autoload": { "psr-4": { diff --git a/src/Entities/Log.php b/src/Entities/Log.php index c444ecac..186dace9 100644 --- a/src/Entities/Log.php +++ b/src/Entities/Log.php @@ -50,7 +50,7 @@ public function __construct($date, $path, $raw) $this->date = $date; $this->path = $path; $this->file = new SplFileInfo($path); - $this->entries = (new LogEntryCollection)->load($raw); + $this->entries = LogEntryCollection::load($raw); } /* ----------------------------------------------------------------- diff --git a/src/Entities/LogCollection.php b/src/Entities/LogCollection.php index 49f89110..3fb53b83 100644 --- a/src/Entities/LogCollection.php +++ b/src/Entities/LogCollection.php @@ -3,7 +3,7 @@ use Arcanedev\LogViewer\Contracts\Utilities\Filesystem as FilesystemContract; use Arcanedev\LogViewer\Exceptions\LogNotFoundException; use Illuminate\Pagination\LengthAwarePaginator; -use Illuminate\Support\Collection; +use Illuminate\Support\LazyCollection; /** * Class LogCollection @@ -11,7 +11,7 @@ * @package Arcanedev\LogViewer\Entities * @author ARCANEDEV */ -class LogCollection extends Collection +class LogCollection extends LazyCollection { /* ----------------------------------------------------------------- | Properties @@ -29,15 +29,20 @@ class LogCollection extends Collection /** * LogCollection constructor. * - * @param array $items + * @param mixed $source */ - public function __construct($items = []) + public function __construct($source = null) { $this->setFilesystem(app(FilesystemContract::class)); - parent::__construct($items); + if (is_null($source)) + $source = function () { + foreach($this->filesystem->dates(true) as $date => $path) { + yield $date => Log::make($date, $path, $this->filesystem->read($date)); + } + }; - if (empty($items)) $this->load(); + parent::__construct($source); } /* ----------------------------------------------------------------- @@ -64,20 +69,6 @@ public function setFilesystem(FilesystemContract $filesystem) | ----------------------------------------------------------------- */ - /** - * Load all logs. - * - * @return \Arcanedev\LogViewer\Entities\LogCollection - */ - private function load() - { - foreach($this->filesystem->dates(true) as $date => $path) { - $this->put($date, Log::make($date, $path, $this->filesystem->read($date))); - } - - return $this; - } - /** * Get a log. * @@ -154,7 +145,7 @@ public function stats() { $stats = []; - foreach ($this->items as $date => $log) { + foreach ($this->all() as $date => $log) { /** @var \Arcanedev\LogViewer\Entities\Log $log */ $stats[$date] = $log->stats(); } @@ -197,7 +188,7 @@ public function tree($trans = false) { $tree = []; - foreach ($this->items as $date => $log) { + foreach ($this->all() as $date => $log) { /** @var \Arcanedev\LogViewer\Entities\Log $log */ $tree[$date] = $log->tree($trans); } @@ -216,7 +207,7 @@ public function menu($trans = true) { $menu = []; - foreach ($this->items as $date => $log) { + foreach ($this->all() as $date => $log) { /** @var \Arcanedev\LogViewer\Entities\Log $log */ $menu[$date] = $log->menu($trans); } diff --git a/src/Entities/LogEntryCollection.php b/src/Entities/LogEntryCollection.php index 2a046aa9..e084e90d 100644 --- a/src/Entities/LogEntryCollection.php +++ b/src/Entities/LogEntryCollection.php @@ -2,7 +2,7 @@ use Arcanedev\LogViewer\Helpers\LogParser; use Illuminate\Pagination\LengthAwarePaginator; -use Illuminate\Support\Collection; +use Illuminate\Support\LazyCollection; /** * Class LogEntryCollection @@ -10,7 +10,7 @@ * @package Arcanedev\LogViewer\Entities * @author ARCANEDEV */ -class LogEntryCollection extends Collection +class LogEntryCollection extends LazyCollection { /* ----------------------------------------------------------------- | Main Methods @@ -24,15 +24,15 @@ class LogEntryCollection extends Collection * * @return self */ - public function load($raw) + public static function load($raw) { - foreach (LogParser::parse($raw) as $entry) { - list($level, $header, $stack) = array_values($entry); + return new static(function () use ($raw) { + foreach (LogParser::parse($raw) as $entry) { + list($level, $header, $stack) = array_values($entry); - $this->push(new LogEntry($level, $header, $stack)); - } - - return $this; + yield new LogEntry($level, $header, $stack); + } + }); } /** diff --git a/src/Http/Controllers/LogViewerController.php b/src/Http/Controllers/LogViewerController.php index c84cfe9c..e0ea6d61 100644 --- a/src/Http/Controllers/LogViewerController.php +++ b/src/Http/Controllers/LogViewerController.php @@ -91,12 +91,12 @@ public function listLogs(Request $request) /** * Show the log. * - * @param string $date * @param \Illuminate\Http\Request $request + * @param string $date * * @return \Illuminate\View\View */ - public function show($date, Request $request) + public function show(Request $request, $date) { $level = 'all'; $log = $this->getLogOrFail($date); @@ -110,13 +110,13 @@ public function show($date, Request $request) /** * Filter the log entries by level. * + * @param \Illuminate\Http\Request $request * @param string $date * @param string $level - * @param \Illuminate\Http\Request $request * * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse */ - public function showByLevel($date, $level, Request $request) + public function showByLevel(Request $request, $date, $level) { if ($level === 'all') return redirect()->route($this->showRoute, [$date]); @@ -132,13 +132,13 @@ public function showByLevel($date, $level, Request $request) /** * Show the log with the search query. * + * @param \Illuminate\Http\Request $request * @param string $date * @param string $level - * @param \Illuminate\Http\Request $request * * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse */ - public function search($date, $level = 'all', Request $request) + public function search(Request $request, $date, $level = 'all') { $query = $request->get('query'); diff --git a/src/Utilities/Factory.php b/src/Utilities/Factory.php index d3806399..7c833784 100644 --- a/src/Utilities/Factory.php +++ b/src/Utilities/Factory.php @@ -152,7 +152,7 @@ public function setPattern( */ public function logs() { - return LogCollection::make()->setFilesystem($this->filesystem); + return (new LogCollection)->setFilesystem($this->filesystem); } /* ----------------------------------------------------------------- diff --git a/tests/Entities/LogCollectionTest.php b/tests/Entities/LogCollectionTest.php index 5f8ca295..c517c793 100644 --- a/tests/Entities/LogCollectionTest.php +++ b/tests/Entities/LogCollectionTest.php @@ -1,6 +1,7 @@ logs = LogCollection::make(); + $this->logs = new LogCollection; } protected function tearDown(): void @@ -57,6 +58,7 @@ public function it_can_get_all_logs() static::assertSame(16, $this->logs->total()); foreach ($this->logs as $date => $log) { + /** @var \Arcanedev\LogViewer\Entities\Log $log */ static::assertLog($log, $date); static::assertCount(8, $log->entries()); static::assertSame(8, $log->entries()->count()); @@ -169,7 +171,7 @@ public function it_can_get_log_menu() /** @test */ public function it_must_throw_a_log_not_found_on_get_method() { - $this->expectException(\Arcanedev\LogViewer\Exceptions\LogNotFoundException::class); + $this->expectException(LogNotFoundException::class); $this->expectExceptionMessage('Log not found in this date [2222-01-01]'); $this->logs->get('2222-01-01'); @@ -178,7 +180,7 @@ public function it_must_throw_a_log_not_found_on_get_method() /** @test */ public function it_must_throw_a_log_not_found_on_log_method() { - $this->expectException(\Arcanedev\LogViewer\Exceptions\LogNotFoundException::class); + $this->expectException(LogNotFoundException::class); $this->expectExceptionMessage('Log not found in this date [2222-01-01]'); $this->logs->log('2222-01-01');