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

[11.x] Adds about command that Checks storage symbolic links status #54001

Closed
wants to merge 13 commits into from
Closed
31 changes: 22 additions & 9 deletions src/Illuminate/Foundation/Console/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class AboutCommand extends Command
/**
* Create a new command instance.
*
* @param \Illuminate\Support\Composer $composer
* @return void
*/
public function __construct(Composer $composer)
Expand Down Expand Up @@ -165,6 +164,7 @@ protected function gatherApplicationInformation()

$formatEnabledStatus = fn ($value) => $value ? '<fg=yellow;options=bold>ENABLED</>' : 'OFF';
$formatCachedStatus = fn ($value) => $value ? '<fg=green;options=bold>CACHED</>' : '<fg=yellow;options=bold>NOT CACHED</>';
$formatStorageLinkedStatus = fn ($value) => $value ? '<fg=green;options=bold>LINKED</>' : '<fg=yellow;options=bold>NOT LINKED</>';
Copy link
Contributor

@selcukcukur selcukcukur Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$formatStorage = fn ($value) => $value ? '<fg=green;options=bold>AVAILABLE</>' : '<fg=yellow;options=bold>NOT AVAILABLE</>';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it can also be set to exists or not exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@selcukcukur Hummm... the command that you'd run would be artisan storage:link which is why I went with Linked. I don't have any strong preferences though.


static::addToSection('Environment', fn () => [
'Application Name' => config('app.name'),
Expand Down Expand Up @@ -214,14 +214,15 @@ protected function gatherApplicationInformation()
'Session' => config('session.driver'),
]));

static::addToSection('Storage', fn () => [
...$this->checkStoragePaths($formatStorageLinkedStatus),
]);

(new Collection(static::$customDataResolvers))->each->__invoke();
}

/**
* Determine whether the given directory has PHP files.
*
* @param string $path
* @return bool
*/
protected function hasPhpFiles(string $path): bool
{
Expand All @@ -231,9 +232,7 @@ protected function hasPhpFiles(string $path): bool
/**
* Add additional data to the output of the "about" command.
*
* @param string $section
* @param callable|string|array $data
* @param string|null $value
* @return void
*/
public static function add(string $section, $data, ?string $value = null)
Expand All @@ -244,9 +243,7 @@ public static function add(string $section, $data, ?string $value = null)
/**
* Add additional data to the output of the "about" command.
*
* @param string $section
* @param callable|string|array $data
* @param string|null $value
* @return void
*/
protected static function addToSection(string $section, $data, ?string $value = null)
Expand Down Expand Up @@ -299,7 +296,6 @@ public static function format($value, ?Closure $console = null, ?Closure $json =
/**
* Format the given string for searching.
*
* @param string $value
* @return string
*/
protected function toSearchKeyword(string $value)
Expand All @@ -318,4 +314,21 @@ public static function flushState()

static::$customDataResolvers = [];
}

/**
* Check storage symbolic links status.
*
* @param callable $formatStorageLinkedStatus Formatter for link status
* @return array<string,mixed> Array of paths and their link status
*/
protected function checkStoragePaths(callable $formatStorageLinkedStatus): array
{
return collect(config('filesystems.links', []))
->mapWithKeys(function ($target, $link) use ($formatStorageLinkedStatus) {
$path = Str::replace(public_path(), '', $link);

return [public_path($path) => static::format(file_exists($link), console: $formatStorageLinkedStatus)];
})
->toArray();
}
}
Loading