From 88a7d0e7cb5435a1a5007f951c3adc63a08bd626 Mon Sep 17 00:00:00 2001 From: Roberto B Date: Thu, 8 Apr 2021 07:34:12 +0200 Subject: [PATCH] Add Storage links check --- src/Console/LaraLensCommand.php | 10 +++++++- src/Lens/Traits/BaseTraits.php | 20 ++++++++++++++++ src/Lens/Traits/FilesystemLens.php | 37 ++++++++++++++++++++++++++++-- src/Lens/Traits/RuntimeLens.php | 1 + 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/Lens/Traits/BaseTraits.php diff --git a/src/Console/LaraLensCommand.php b/src/Console/LaraLensCommand.php index b030fea..c6c91db 100644 --- a/src/Console/LaraLensCommand.php +++ b/src/Console/LaraLensCommand.php @@ -70,10 +70,18 @@ private function printOutput(array $headers, array $rows) foreach ($rows as $key => $row) { $label = Arr::get($row, "label", ""); $value = Arr::get($row, "value", ""); + if (is_array($value)) { + $value = implode(",", $value); + } $isLine = Arr::get($row, "isLine", false); $lineType = Arr::get($row, "lineType", ResultLens::LINE_TYPE_DEFAULT); - if (strlen($value) > $this->widthValue || $isLine || $lineType === ResultLens::LINE_TYPE_ERROR || $lineType === ResultLens::LINE_TYPE_WARNING) { + if ( + strlen($value) > $this->widthValue || + $isLine || + $lineType === ResultLens::LINE_TYPE_ERROR || + $lineType === ResultLens::LINE_TYPE_WARNING + ) { $rowsLine[] = $row; } else { $row["label"] = $this->formatCell($label, $this->widthLabel); diff --git a/src/Lens/Traits/BaseTraits.php b/src/Lens/Traits/BaseTraits.php new file mode 100644 index 0000000..db2bdfc --- /dev/null +++ b/src/Lens/Traits/BaseTraits.php @@ -0,0 +1,20 @@ + 3) { + if (Str::startsWith($value, $curDir)) { + $value = "." . Str::after($value, $curDir); + } + } + return $value; + } +} diff --git a/src/Lens/Traits/FilesystemLens.php b/src/Lens/Traits/FilesystemLens.php index 2cefb7b..6613fd1 100644 --- a/src/Lens/Traits/FilesystemLens.php +++ b/src/Lens/Traits/FilesystemLens.php @@ -7,10 +7,16 @@ trait FilesystemLens { + use BaseTraits; + + protected function links() + { + return config("filesystems.links") ?? + [public_path('storage') => storage_path('app/public')]; + //return $this->laravel['config']['filesystems.links'] ?? + } public function checkFiles() { - - $results = new ResultLens(); $envExists = file_exists(App::environmentFilePath()); if ($envExists) { @@ -49,6 +55,33 @@ public function checkFiles() "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; } } diff --git a/src/Lens/Traits/RuntimeLens.php b/src/Lens/Traits/RuntimeLens.php index 86b368e..11df9f9 100644 --- a/src/Lens/Traits/RuntimeLens.php +++ b/src/Lens/Traits/RuntimeLens.php @@ -8,6 +8,7 @@ trait RuntimeLens { + private function appCaller($results, $functions) { $curDir = getcwd();