-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Using the new LazyCollection to load the log files
- Loading branch information
1 parent
a373c51
commit b9d5a01
Showing
12 changed files
with
51 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters