attachmentGateway = $attachmentGateway; $this->fileReader = $fileReader; $this->ticketGateway = $ticketGateway; $this->userToTicketChecker = $userToTicketChecker; } function getAttachmentContentsForTicket($ticketId, $attachmentId, $userContext, $heskSettings) { $ticket = $this->ticketGateway->getTicketById($ticketId, $heskSettings); if ($ticket === null) { throw new ApiFriendlyException("Ticket {$ticketId} not found!", "Ticket Not Found", 404); } if (!$this->userToTicketChecker->isTicketAccessibleToUser($userContext, $ticket, $heskSettings)) { throw new AccessViolationException("User does not have access to attachment {$attachmentId}!"); } $attachment = $this->attachmentGateway->getAttachmentById($attachmentId, $heskSettings); $contents = base64_encode($this->fileReader->readFromFile( $attachment->savedName, $heskSettings['attach_dir'])); return $contents; } }