/** * Initiate the download request, create a new instance with given parameters. * * @param string $documentHash The documentHash generated using {@link SecureDownloader::generateHash()} * @param string $accessKey A key (hash is nice) that is compared to the one used set when the document hash has been generated. * * @return DownloadRequest */ private function initiateDownloadRequest($documentHash, $accessKey) { $cacheItem = $this->stash->getItem($this->stashPrefixKey . '/' . $documentHash); // A voir la méthode d'invalidation $downloadRequest = $cacheItem->get(Invalidation::NONE); if ($cacheItem->isMiss()) { // Delete stash item $cacheItem->clear(); // Mark downloadRequest as expired (documentHash expired) $downloadRequest = new DownloadRequest(); $downloadRequest->addError(new DownloadRequestError(ErrorCode::DOCUMENT_EXPIRED, 'Document hash expired / missing.')); return $downloadRequest; } // Assume that we have a DownloadRequest object if (!$downloadRequest instanceof DownloadRequest) { $downloadRequest = new DownloadRequest(); $downloadRequest->addError(new DownloadRequestError(ErrorCode::INVALID_STORED_DOCUMENT_TYPE, 'Given Hash doesn\'t match a DownloadRequest object.')); return $downloadRequest; } /** @var DownloadRequest $downloadRequest Here we are sure it is */ // Check the authorization to access the file if (!$downloadRequest->isAccessKeyValid($accessKey)) { $downloadRequest->addError(new DownloadRequestError(ErrorCode::INVALID_ACCESS_KEY, 'Invalid access key provided for given document hash.')); return $downloadRequest; } return $downloadRequest; }
/** * Return the given document filePath * * @return string */ public function getDocumentPath() { return $this->downloadRequest->getFilePath(); }