Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Console;
4
 
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
 
8
#[AsCommand(name: 'storage:link')]
9
class StorageLinkCommand extends Command
10
{
11
    /**
12
     * The console command signature.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'storage:link
17
                {--relative : Create the symbolic link using relative paths}
18
                {--force : Recreate existing symbolic links}';
19
 
20
    /**
21
     * The name of the console command.
22
     *
23
     * This name is used to identify the command during lazy loading.
24
     *
25
     * @var string|null
26
     *
27
     * @deprecated
28
     */
29
    protected static $defaultName = 'storage:link';
30
 
31
    /**
32
     * The console command description.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Create the symbolic links configured for the application';
37
 
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return void
42
     */
43
    public function handle()
44
    {
45
        $relative = $this->option('relative');
46
 
47
        foreach ($this->links() as $link => $target) {
48
            if (file_exists($link) && ! $this->isRemovableSymlink($link, $this->option('force'))) {
49
                $this->components->error("The [$link] link already exists.");
50
                continue;
51
            }
52
 
53
            if (is_link($link)) {
54
                $this->laravel->make('files')->delete($link);
55
            }
56
 
57
            if ($relative) {
58
                $this->laravel->make('files')->relativeLink($target, $link);
59
            } else {
60
                $this->laravel->make('files')->link($target, $link);
61
            }
62
 
63
            $this->components->info("The [$link] link has been connected to [$target].");
64
        }
65
    }
66
 
67
    /**
68
     * Get the symbolic links that are configured for the application.
69
     *
70
     * @return array
71
     */
72
    protected function links()
73
    {
74
        return $this->laravel['config']['filesystems.links'] ??
75
               [public_path('storage') => storage_path('app/public')];
76
    }
77
 
78
    /**
79
     * Determine if the provided path is a symlink that can be removed.
80
     *
81
     * @param  string  $link
82
     * @param  bool  $force
83
     * @return bool
84
     */
85
    protected function isRemovableSymlink(string $link, bool $force): bool
86
    {
87
        return is_link($link) && $force;
88
    }
89
}