1 | <?php |
||
11 | class Filesystem |
||
12 | { |
||
13 | /** |
||
14 | * @var \Illuminate\Contracts\Filesystem\Factory |
||
15 | */ |
||
16 | protected $filesystem; |
||
17 | |||
18 | /** |
||
19 | * @var \Illuminate\Contracts\Config\Repository |
||
20 | */ |
||
21 | protected $config; |
||
22 | |||
23 | /** |
||
24 | * @param \Illuminate\Contracts\Filesystem\Factory $filesystems |
||
25 | * @param \Illuminate\Contracts\Config\Repository $config |
||
26 | */ |
||
27 | public function __construct(Factory $filesystems, ConfigRepository $config) |
||
32 | |||
33 | /* |
||
34 | * Add a file to the mediaLibrary for the given media. |
||
35 | */ |
||
36 | public function add(string $file, Media $media, string $targetFileName = '') |
||
44 | |||
45 | /* |
||
46 | * Copy a file to the medialibrary for the given $media. |
||
47 | */ |
||
48 | public function copyToMediaLibrary(string $file, Media $media, bool $conversions = false, string $targetFileName = '') |
||
49 | { |
||
50 | $destination = $this->getMediaDirectory($media, $conversions). |
||
51 | ($targetFileName == '' ? pathinfo($file, PATHINFO_BASENAME) : $targetFileName); |
||
52 | |||
53 | if ($media->getDiskDriverName() === 'local') { |
||
54 | $this->filesystem |
||
55 | ->disk($media->disk) |
||
56 | ->put($destination, fopen($file, 'r+')); |
||
57 | |||
58 | return; |
||
59 | } |
||
60 | |||
61 | $this->filesystem |
||
62 | ->disk($media->disk) |
||
63 | ->getDriver() |
||
64 | ->put($destination, fopen($file, 'r+'), $this->getRemoteHeadersForFile($file)); |
||
65 | } |
||
66 | |||
67 | /* |
||
68 | * Get the headers to be used when copying the |
||
69 | * given file to a remote filesytem. |
||
70 | */ |
||
71 | public function getRemoteHeadersForFile(string $file) : array |
||
79 | |||
80 | /* |
||
81 | * Copy a file from the medialibrary to the given targetFile. |
||
82 | */ |
||
83 | public function copyFromMediaLibrary(Media $media, string $targetFile) |
||
93 | |||
94 | /* |
||
95 | * Remove all files for the given media. |
||
96 | */ |
||
97 | public function removeFiles(Media $media) |
||
108 | |||
109 | /* |
||
110 | * Rename a file for the given media. |
||
111 | */ |
||
112 | public function renameFile(Media $media, string $oldName) |
||
119 | |||
120 | /* |
||
121 | * Return the directory where all files of the given media are stored. |
||
122 | */ |
||
123 | public function getMediaDirectory(Media $media, bool $conversion = false) : string |
||
135 | |||
136 | /* |
||
137 | * Return the directory where all conversions of the given media are stored. |
||
138 | */ |
||
139 | public function getConversionDirectory(Media $media) : string |
||
143 | } |
||
144 |