Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle false returns on glob calls #260

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LogViewerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ protected function getLaravelLogFilePaths(): array
return array_values(array_reverse($files));
}

protected function getFilePathsMatchingPattern($pattern)
protected function getFilePathsMatchingPattern($pattern): array
{
// The GLOB_BRACE flag is not available on some non GNU systems, like Solaris or Alpine Linux.

if (str_contains($pattern, '**')) {
return Utils::glob_recursive($pattern);
}

return glob($pattern);
return glob($pattern) ?: [];
}

public function basePathForLogs(): string
Expand Down
7 changes: 4 additions & 3 deletions src/Utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ public static function shortMd5(string $content, int $length = 8): string
return substr(md5($content), -$length, $length);
}

public static function glob_recursive($pattern, $flags = 0): bool|array
public static function glob_recursive($pattern, $flags = 0): array
{
$files = glob($pattern, $flags);
$files = glob($pattern, $flags) ?: [];
$folders = glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) ?: [];

foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
foreach ($folders as $dir) {
$files = array_merge($files, static::glob_recursive($dir.'/'.basename($pattern), $flags));
}

Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Authorization/CanDownloadFoldersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Gate;
use Opcodes\LogViewer\Facades\LogViewer;
use Opcodes\LogViewer\LogFolder;

use function Pest\Laravel\get;

test('can download every folder by default', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Authorization/CanDownloadLogFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Gate;
use Opcodes\LogViewer\LogFile;

use function Pest\Laravel\get;

test('can download every file by default', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Authorization/CanViewLogViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Gate;
use Opcodes\LogViewer\Facades\LogViewer;

use function Pest\Laravel\get;

test('can define an "auth" callback for authorization', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/ClearingFileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Opcodes\LogViewer\Facades\LogViewer;
use Opcodes\LogViewer\LogIndex;
use Opcodes\LogViewer\Utils\GenerateCacheKey;

use function PHPUnit\Framework\assertNotSame;

beforeEach(function () {
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/LogViewerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Opcodes\LogViewer\Facades\LogViewer;

use function PHPUnit\Framework\assertContains;
use function PHPUnit\Framework\assertNotContains;

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Opcodes\LogViewer\LogLevels\LaravelLogLevel;
use Opcodes\LogViewer\Logs\LaravelLog;

use function PHPUnit\Framework\assertEquals;

it('can understand the default Laravel log format', function () {
Expand Down