Skip to content

Commit

Permalink
Merge pull request #280 from ARCANEDEV/update-laravel_6.0_support
Browse files Browse the repository at this point in the history
Adding Laravel 6.0 support
  • Loading branch information
arcanedev-maroc authored Sep 4, 2019
2 parents a373c51 + b9d5a01 commit bfb20e3
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
runs: 2
php_code_sniffer:
enabled: true
config:
Expand Down
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ language: php
sudo: false

php:
- 7.1.3
- 7.1
- 7.2
- 7.3
- nightly
Expand All @@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion _docs/0.Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions _docs/1.Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,13 +40,15 @@ 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.*"
[log_viewer_4_4_x]: https://img.shields.io/badge/version-4.4.*-blue.svg?style=flat-square "LogViewer v4.4.*"
[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

Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/* -----------------------------------------------------------------
Expand Down
37 changes: 14 additions & 23 deletions src/Entities/LogCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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
*
* @package Arcanedev\LogViewer\Entities
* @author ARCANEDEV <[email protected]>
*/
class LogCollection extends Collection
class LogCollection extends LazyCollection
{
/* -----------------------------------------------------------------
| Properties
Expand All @@ -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);
}

/* -----------------------------------------------------------------
Expand All @@ -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.
*
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Entities/LogEntryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

use Arcanedev\LogViewer\Helpers\LogParser;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;

/**
* Class LogEntryCollection
*
* @package Arcanedev\LogViewer\Entities
* @author ARCANEDEV <[email protected]>
*/
class LogEntryCollection extends Collection
class LogEntryCollection extends LazyCollection
{
/* -----------------------------------------------------------------
| Main Methods
Expand All @@ -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);
}
});
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand All @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function setPattern(
*/
public function logs()
{
return LogCollection::make()->setFilesystem($this->filesystem);
return (new LogCollection)->setFilesystem($this->filesystem);
}

/* -----------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions tests/Entities/LogCollectionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Arcanedev\LogViewer\Tests\Entities;

use Arcanedev\LogViewer\Entities\LogCollection;
use Arcanedev\LogViewer\Exceptions\LogNotFoundException;
use Arcanedev\LogViewer\Tests\TestCase;

/**
Expand Down Expand Up @@ -28,7 +29,7 @@ protected function setUp(): void
{
parent::setUp();

$this->logs = LogCollection::make();
$this->logs = new LogCollection;
}

protected function tearDown(): void
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit bfb20e3

Please sign in to comment.