getRealPath(); if (isset($attachment['decrypted_attachment']) and $attachment['decrypted_attachment'] !== false) { $attachment['decrypted_attachment'] = $attachment['decrypted_attachment']->getRealPath(); } return $attachment; }, $service->fetchFullAttachments()); return $this->withJson($response, compact('attachments')); } protected function fileToArray(\SplFileInfo $info): array { return [ 'filename' => $info->getFilename(), 'path' => $info->getPath(), 'full_name' => $info->getRealPath(), 'extension' => $info->getExtension() ]; } public function get(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface { $body = $request->getBody()->getContents(); $json = json_decode($body); if (!is_array($json)) { $json = [$json]; } $output = ['input' => $json, 'attachments' => []]; foreach ($json as $attachment) { $output['attachments'] []= $this->fileToArray($service->getAttachment($json->attachment)); } return $this->withJson($response, $output); } public function decrypt(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface { $body = $request->getBody()->getContents(); $json = json_decode($body); if (!is_array($json)) { $json = [$json]; } $output = ['input' => $json, 'attachments' => []]; foreach ($json as $attachment) { $output['attachments'] []= $this->fileToArray($service->removeEncryption($attachment)); } return $this->withJson($response, $output); } }