implementationClassNameMap = $implementationClassNameMap; $this->injectableFactory = $injectableFactory; } private function getImplementation(?string $storage = null) { if (!$storage) { $storage = 'EspoUploadDir'; } if (!array_key_exists($storage, $this->implementations)) { if (!array_key_exists($storage, $this->implementationClassNameMap)) { throw new Error("FileStorageManager: Unknown storage '{$storage}'"); } $className = $this->implementationClassNameMap[$storage]; $this->implementations[$storage] = $this->injectableFactory->create($className); } return $this->implementations[$storage]; } /** * Whether a file exists in a storage. */ public function isFile(Attachment $attachment) : bool { $implementation = $this->getImplementation($attachment->get('storage')); return $implementation->isFile($attachment); } /** * Get file contents. */ public function getContents(Attachment $attachment) : ?string { $implementation = $this->getImplementation($attachment->get('storage')); return $implementation->getContents($attachment); } /** * Store file contents. */ public function putContents(Attachment $attachment, string $contents) { $implementation = $this->getImplementation($attachment->get('storage')); $implementation->putContents($attachment, $contents); } /** * Remove a file. */ public function unlink(Attachment $attachment) { $implementation = $this->getImplementation($attachment->get('storage')); $implementation->unlink($attachment); } /** * Get a file path. */ public function getLocalFilePath(Attachment $attachment) : string { $implementation = $this->getImplementation($attachment->get('storage')); return $implementation->getLocalFilePath($attachment); } /** * Whether a file can be downloaded by URL. */ public function hasDownloadUrl(Attachment $attachment) : bool { $implementation = $this->getImplementation($attachment->get('storage')); return $implementation->hasDownloadUrl($attachment); } /** * Get download URL. */ public function getDownloadUrl(Attachment $attachment) : string { $implementation = $this->getImplementation($attachment->get('storage')); return $implementation->getDownloadUrl($attachment); } }