@@ -228,22 +228,34 @@ public function showValidateFile(bool $validateFile = true): self {
228228 return $ this ;
229229 }
230230
231- /**
232- * @return static
233- */
234- public function setFileByType (string $ type , $ identifier ): self {
231+ private function setFileOrFail (callable $ resolver ): self {
235232 try {
236- $ method = $ type === 'FileId ' ? 'getById ' : 'getBy ' . $ type ;
237- /** @var File */
238- $ file = call_user_func ([$ this ->fileMapper , $ method ], $ identifier );
233+ $ file = $ resolver ();
239234 } catch (\Throwable ) {
240235 throw new LibresignException ($ this ->l10n ->t ('Invalid data to validate file ' ), 404 );
241236 }
242- if (!$ file ) {
237+
238+ if (!$ file instanceof File) {
243239 throw new LibresignException ($ this ->l10n ->t ('Invalid file identifier ' ), 404 );
244240 }
245- $ this ->setFile ($ file );
246- return $ this ;
241+
242+ return $ this ->setFile ($ file );
243+ }
244+
245+ public function setFileById (int $ fileId ): self {
246+ return $ this ->setFileOrFail (fn () => $ this ->fileMapper ->getById ($ fileId ));
247+ }
248+
249+ public function setFileByUuid (string $ uuid ): self {
250+ return $ this ->setFileOrFail (fn () => $ this ->fileMapper ->getByUuid ($ uuid ));
251+ }
252+
253+ public function setFileBySignerUuid (string $ uuid ): self {
254+ return $ this ->setFileOrFail (fn () => $ this ->fileMapper ->getBySignerUuid ($ uuid ));
255+ }
256+
257+ public function setFileByNodeId (int $ nodeId ): self {
258+ return $ this ->setFileOrFail (fn () => $ this ->fileMapper ->getByNodeId ($ nodeId ));
247259 }
248260
249261 public function validateUploadedFile (array $ file ): void {
@@ -302,6 +314,10 @@ public function getStatus(): int {
302314 return $ this ->file ->getStatus ();
303315 }
304316
317+ public function isLibresignFile (int $ nodeId ): bool {
318+ return $ this ->fileMapper ->fileIdExists ($ nodeId );
319+ }
320+
305321 public function getSignedNodeId (): ?int {
306322 $ status = $ this ->file ->getStatus ();
307323
0 commit comments