Skip to content

Commit

Permalink
Merge pull request #42 from Hi-Folks/feature/39-check-storage-links
Browse files Browse the repository at this point in the history
Add Storage links check
  • Loading branch information
roberto-butti authored Apr 8, 2021
2 parents 34627c8 + 88a7d0e commit 4ac9be9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/Console/LaraLensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/Lens/Traits/BaseTraits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace HiFolks\LaraLens\Lens\Traits;

use Illuminate\Support\Str;

trait BaseTraits
{
protected function stripPrefixDir($value)
{
//$curDir = getcwd();
$curDir = base_path();
if (Str::length($curDir) > 3) {
if (Str::startsWith($value, $curDir)) {
$value = "." . Str::after($value, $curDir);
}
}
return $value;
}
}
37 changes: 35 additions & 2 deletions src/Lens/Traits/FilesystemLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/Lens/Traits/RuntimeLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

trait RuntimeLens
{

private function appCaller($results, $functions)
{
$curDir = getcwd();
Expand Down

0 comments on commit 4ac9be9

Please sign in to comment.