- protected FilesystemManager $fileSystem;
-
- /**
- * AttachmentService constructor.
- */
- public function __construct(FilesystemManager $fileSystem)
- {
- $this->fileSystem = $fileSystem;
- }
-
- /**
- * Get the storage that will be used for storing files.
- */
- protected function getStorageDisk(): Storage
- {
- return $this->fileSystem->disk($this->getStorageDiskName());
- }
-
- /**
- * Get the name of the storage disk to use.
- */
- protected function getStorageDiskName(): string
- {
- $storageType = config('filesystems.attachments');
-
- // Change to our secure-attachment disk if any of the local options
- // are used to prevent escaping that location.
- if ($storageType === 'local' || $storageType === 'local_secure') {
- $storageType = 'local_secure_attachments';
- }
-
- return $storageType;
- }
-
- /**
- * Change the originally provided path to fit any disk-specific requirements.
- * This also ensures the path is kept to the expected root folders.
- */
- protected function adjustPathForStorageDisk(string $path): string
- {
- $path = Util::normalizePath(str_replace('uploads/files/', '', $path));
-
- if ($this->getStorageDiskName() === 'local_secure_attachments') {
- return $path;
- }
-
- return 'uploads/files/' . $path;