Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 21, 2020
1 parent dace64c commit 24b705e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"swiftmailer/swiftmailer": "^6.0",
"symfony/console": "^5.0",
"symfony/error-handler": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/finder": "^5.0",
"symfony/http-foundation": "^5.0",
"symfony/http-kernel": "^5.0",
Expand Down Expand Up @@ -138,6 +137,7 @@
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).",
"symfony/cache": "Required to PSR-6 cache bridge (^5.0).",
"symfony/filesystem": "Required to create relative storage directory symbolic links (^5.0).",
"symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0).",
"wildbit/swiftmailer-postmark": "Required to use Postmark mail driver (^3.0)."
},
Expand Down
23 changes: 20 additions & 3 deletions src/Illuminate/Foundation/Console/StorageLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Foundation\Console;

use Exception;
use Illuminate\Console\Command;
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;

Expand All @@ -12,7 +13,7 @@ class StorageLinkCommand extends Command
*
* @var string
*/
protected $signature = 'storage:link {--absolute : Create links using absolute paths}';
protected $signature = 'storage:link {--relative : Create the symbolic link using relative paths}';

/**
* The console command description.
Expand All @@ -32,8 +33,8 @@ public function handle()
if (file_exists($link)) {
$this->error("The [$link] link already exists.");
} else {
if (! $this->option('absolute')) {
$target = (new SymfonyFilesystem)->makePathRelative($target, dirname($link));
if ($this->option('relative')) {
$target = $this->getRelativeTarget($link, $target);
}

$this->laravel->make('files')->link($target, $link);
Expand All @@ -55,4 +56,20 @@ protected function links()
return $this->laravel['config']['filesystems.links'] ??
[public_path('storage') => storage_path('app/public')];
}

/**
* Get the relative path to the target.
*
* @param string $link
* @param string $target
* @return string
*/
protected function getRelativeTarget($link, $target)
{
if (! class_exists(SymfonyFilesystem::class)) {
throw new Exception("Please install the symfony/filesystem Composer package to create relative links.");
}

return (new SymfonyFilesystem)->makePathRelative($target, dirname($link));
}
}

0 comments on commit 24b705e

Please sign in to comment.