Completed
Pull Request — master (#66)
by
unknown
02:07
created

Server::applyMiddleware()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TusPhp\Tus;
4
5
use TusPhp\File;
6
use Carbon\Carbon;
7
use TusPhp\Request;
8
use TusPhp\Response;
9
use Ramsey\Uuid\Uuid;
10
use TusPhp\Cache\Cacheable;
11
use TusPhp\Middleware\Middleware;
12
use TusPhp\Exception\FileException;
13
use TusPhp\Exception\ConnectionException;
14
use TusPhp\Exception\OutOfRangeException;
15
use Symfony\Component\HttpFoundation\BinaryFileResponse;
16
use Symfony\Component\HttpFoundation\Response as HttpResponse;
17
18
class Server extends AbstractTus
19
{
20
    /** @const string Tus Creation Extension */
21
    const TUS_EXTENSION_CREATION = 'creation';
22
23
    /** @const string Tus Termination Extension */
24
    const TUS_EXTENSION_TERMINATION = 'termination';
25
26
    /** @const string Tus Checksum Extension */
27
    const TUS_EXTENSION_CHECKSUM = 'checksum';
28
29
    /** @const string Tus Expiration Extension */
30
    const TUS_EXTENSION_EXPIRATION = 'expiration';
31
32
    /** @const string Tus Concatenation Extension */
33
    const TUS_EXTENSION_CONCATENATION = 'concatenation';
34
35
    /** @const array All supported tus extensions */
36
    const TUS_EXTENSIONS = [
37
        self::TUS_EXTENSION_CREATION,
38
        self::TUS_EXTENSION_TERMINATION,
39
        self::TUS_EXTENSION_CHECKSUM,
40
        self::TUS_EXTENSION_EXPIRATION,
41
        self::TUS_EXTENSION_CONCATENATION,
42
    ];
43
44
    /** @const int 460 Checksum Mismatch */
45
    const HTTP_CHECKSUM_MISMATCH = 460;
46
47
    /** @const string Default checksum algorithm */
48
    const DEFAULT_CHECKSUM_ALGORITHM = 'sha256';
49
50
    /** @var Request */
51
    protected $request;
52
53
    /** @var Response */
54
    protected $response;
55
56
    /** @var string */
57
    protected $uploadDir;
58
59
    /** @var string */
60
    protected $uploadKey;
61
62
    /** @var Middleware */
63
    protected $middleware;
64
65
    /**
66
     * @var int Max upload size in bytes
67
     *          Default 0, no restriction.
68
     */
69
    protected $maxUploadSize = 0;
70
71
    /**
72
     * TusServer constructor.
73
     *
74
     * @param Cacheable|string $cacheAdapter
75
     */
76 3
    public function __construct($cacheAdapter = 'file')
77
    {
78 3
        $this->request    = new Request;
79 3
        $this->response   = new Response;
80 3
        $this->middleware = new Middleware;
81 3
        $this->uploadDir  = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'uploads';
82
83 3
        $this->setCache($cacheAdapter);
84 3
    }
85
86
    /**
87
     * Set upload dir.
88
     *
89
     * @param string $path
90
     *
91
     * @return Server
92
     */
93 2
    public function setUploadDir(string $path) : self
94
    {
95 2
        $this->uploadDir = $path;
96
97 2
        return $this;
98
    }
99
100
    /**
101
     * Get upload dir.
102
     *
103
     * @return string
104
     */
105 1
    public function getUploadDir() : string
106
    {
107 1
        return $this->uploadDir;
108
    }
109
110
    /**
111
     * Get request.
112
     *
113
     * @return Request
114
     */
115 1
    public function getRequest() : Request
116
    {
117 1
        return $this->request;
118
    }
119
120
    /**
121
     * Get request.
122
     *
123
     * @return Response
124
     */
125 1
    public function getResponse() : Response
126
    {
127 1
        return $this->response;
128
    }
129
130
    /**
131
     * Get file checksum.
132
     *
133
     * @param string $filePath
134
     *
135
     * @return string
136
     */
137 1
    public function getServerChecksum(string $filePath) : string
138
    {
139 1
        return hash_file($this->getChecksumAlgorithm(), $filePath);
140
    }
141
142
    /**
143
     * Get checksum algorithm.
144
     *
145
     * @return string|null
146
     */
147 1
    public function getChecksumAlgorithm()
148
    {
149 1
        $checksumHeader = $this->getRequest()->header('Upload-Checksum');
150
151 1
        if (empty($checksumHeader)) {
152 1
            return self::DEFAULT_CHECKSUM_ALGORITHM;
153
        }
154
155 1
        list($checksumAlgorithm, /* $checksum */) = explode(' ', $checksumHeader);
156
157 1
        return $checksumAlgorithm;
158
    }
159
160
    /**
161
     * Set upload key.
162
     *
163
     * @param string $key
164
     *
165
     * @return Server
166
     */
167 1
    public function setUploadKey(string $key) : self
168
    {
169 1
        $this->uploadKey = $key;
170
171 1
        return $this;
172
    }
173
174
    /**
175
     * Get upload key from header.
176
     *
177
     * @return string|HttpResponse
178
     */
179 4
    public function getUploadKey()
180
    {
181 4
        if ( ! empty($this->uploadKey)) {
182 1
            return $this->uploadKey;
183
        }
184
185 3
        $key = $this->getRequest()->header('Upload-Key') ?? Uuid::uuid4()->toString();
186
187 3
        if (empty($key)) {
188 1
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
189
        }
190
191 2
        $this->uploadKey = $key;
192
193 2
        return $this->uploadKey;
194
    }
195
196
    /**
197
     * Set middleware.
198
     *
199
     * @param Middleware $middleware
200
     *
201
     * @return self
202
     */
203 1
    public function setMiddleware(Middleware $middleware) : self
204
    {
205 1
        $this->middleware = $middleware;
206
207 1
        return $this;
208
    }
209
210
    /**
211
     * Get middleware.
212
     *
213
     * @return Middleware
214
     */
215 1
    public function middleware() : Middleware
216
    {
217 1
        return $this->middleware;
218
    }
219
220
    /**
221
     * Set max upload size.
222
     *
223
     * @param int $uploadSize
224
     *
225
     * @return Server
226
     */
227 2
    public function setMaxUploadSize(int $uploadSize) : self
228
    {
229 2
        $this->maxUploadSize = $uploadSize;
230
231 2
        return $this;
232
    }
233
234
    /**
235
     * Get max upload size.
236
     *
237
     * @return int
238
     */
239 1
    public function getMaxUploadSize() : int
240
    {
241 1
        return $this->maxUploadSize;
242
    }
243
244
    /**
245
     * Handle all HTTP request.
246
     *
247
     * @return HttpResponse|BinaryFileResponse
248
     */
249 3
    public function serve()
250
    {
251 3
        $this->applyMiddleware();
252
253 3
        $requestMethod = $this->getRequest()->method();
254
255 3
        if ( ! in_array($requestMethod, $this->getRequest()->allowedHttpVerbs())) {
256 1
            return $this->response->send(null, HttpResponse::HTTP_METHOD_NOT_ALLOWED);
257
        }
258
259 2
        $method = 'handle' . ucfirst(strtolower($requestMethod));
260
261 2
        return $this->{$method}();
262
    }
263
264
    /**
265
     * Emit events for Laravel and Symfony (TODO);
266
     *
267
     * @param string $eventClass
268
     * @param File $file
269
     *
270
     * @return null
271
     */
272
    public function event(string $eventClass, File $file, ...$vars)
273
    {
274
        // Laravel
275
        if (function_exists('event')) {
276
            event(new $eventClass($file, ...$vars));
277
        }
278
    }
279
280
    /**
281
     * Apply middleware.
282
     *
283
     * @return null
284
     */
285 1
    protected function applyMiddleware()
286
    {
287 1
        $middleware = $this->middleware()->list();
288
289 1
        foreach ($middleware as $m) {
290 1
            $m->handle($this->getRequest(), $this->getResponse());
291
        }
292 1
    }
293
294
    /**
295
     * Handle OPTIONS request.
296
     *
297
     * @return HttpResponse
298
     */
299 2
    protected function handleOptions() : HttpResponse
300
    {
301
        $headers = [
302 2
            'Allow' => implode(',', $this->request->allowedHttpVerbs()),
303 2
            'Tus-Version' => self::TUS_PROTOCOL_VERSION,
304 2
            'Tus-Extension' => implode(',', self::TUS_EXTENSIONS),
305 2
            'Tus-Checksum-Algorithm' => $this->getSupportedHashAlgorithms(),
306
        ];
307
308 2
        $maxUploadSize = $this->getMaxUploadSize();
309
310 2
        if ($maxUploadSize > 0) {
311 1
            $headers['Tus-Max-Size'] = $maxUploadSize;
312
        }
313
314 2
        return $this->response->send(null, HttpResponse::HTTP_OK, $headers);
315
    }
316
317
    /**
318
     * Handle HEAD request.
319
     *
320
     * @return HttpResponse
321
     */
322 5
    protected function handleHead() : HttpResponse
323
    {
324 5
        $key = $this->request->key();
325
326 5
        if ( ! $fileMeta = $this->cache->get($key)) {
327 1
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
328
        }
329
330 4
        $offset = $fileMeta['offset'] ?? false;
331
332 4
        if (false === $offset) {
333 1
            return $this->response->send(null, HttpResponse::HTTP_GONE);
334
        }
335
336 3
        return $this->response->send(null, HttpResponse::HTTP_OK, $this->getHeadersForHeadRequest($fileMeta));
337
    }
338
339
    /**
340
     * Handle POST request.
341
     *
342
     * @return HttpResponse
343
     */
344 5
    protected function handlePost() : HttpResponse
345
    {
346 5
        $fileName   = $this->getRequest()->extractFileName();
347 5
        $uploadType = self::UPLOAD_TYPE_NORMAL;
348
349 5
        if (empty($fileName)) {
350 1
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
351
        }
352
353 4
        if ( ! $this->verifyUploadSize()) {
354 1
            return $this->response->send(null, HttpResponse::HTTP_REQUEST_ENTITY_TOO_LARGE);
355
        }
356
357 3
        $uploadKey = $this->getUploadKey();
358 3
        $filePath  = $this->uploadDir . DIRECTORY_SEPARATOR . $fileName;
359
360 3
        if ($this->getRequest()->isFinal()) {
361 1
            return $this->handleConcatenation($fileName, $filePath);
362
        }
363
364 2
        if ($this->getRequest()->isPartial()) {
365 1
            $filePath   = $this->getPathForPartialUpload($uploadKey) . $fileName;
366 1
            $uploadType = self::UPLOAD_TYPE_PARTIAL;
367
        }
368
369 2
        $checksum = $this->getClientChecksum();
370 2
        $location = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
371
372 2
        $file = $this->buildFile([
373 2
            'name' => $fileName,
374 2
            'offset' => 0,
375 2
            'size' => $this->getRequest()->header('Upload-Length'),
376 2
            'file_path' => $filePath,
377 2
            'location' => $location,
378 2
        ])->setChecksum($checksum);
379
380 2
        $this->cache->set($uploadKey, $file->details() + ['upload_type' => $uploadType]);
381
382 2
        $response = $this->response->send(
383 2
            null,
384 2
            HttpResponse::HTTP_CREATED,
385
            [
386 2
                'Location' => $location,
387 2
                'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
388
            ]
389
        );
390
391 2
        $this->event(\TusPhp\Events\Created::class, $file, $this->getRequest(), $this->getResponse());
392
393 2
        return $response;
394
    }
395
396
    /**
397
     * Handle file concatenation.
398
     *
399
     * @param string $fileName
400
     * @param string $filePath
401
     *
402
     * @return HttpResponse
403
     */
404 2
    protected function handleConcatenation(string $fileName, string $filePath) : HttpResponse
405
    {
406 2
        $partials  = $this->getRequest()->extractPartials();
407 2
        $uploadKey = $this->getUploadKey();
408 2
        $files     = $this->getPartialsMeta($partials);
409 2
        $filePaths = array_column($files, 'file_path');
410 2
        $location  = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
411
412 2
        $file = $this->buildFile([
413 2
            'name' => $fileName,
414 2
            'offset' => 0,
415 2
            'size' => 0,
416 2
            'file_path' => $filePath,
417 2
            'location' => $location,
418 2
        ])->setFilePath($filePath);
419
420 2
        $file->setOffset($file->merge($files));
421
422
        // Verify checksum.
423 2
        $checksum = $this->getServerChecksum($filePath);
424
425 2
        if ($checksum !== $this->getClientChecksum()) {
426 1
            return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
427
        }
428
429 1
        $this->cache->set($uploadKey, $file->details() + ['upload_type' => self::UPLOAD_TYPE_FINAL]);
430
431
        // Cleanup.
432 1
        if ($file->delete($filePaths, true)) {
433 1
            $this->cache->deleteAll($partials);
434
        }
435
436 1
        return $this->response->send(
437 1
            ['data' => ['checksum' => $checksum]],
438 1
            HttpResponse::HTTP_CREATED,
439
            [
440 1
                'Location' => $location,
441
            ]
442
        );
443
    }
444
445
    /**
446
     * Handle PATCH request.
447
     *
448
     * @return HttpResponse
449
     */
450 8
    protected function handlePatch() : HttpResponse
451
    {
452 8
        $uploadKey = $this->request->key();
453
454 8
        if ( ! $meta = $this->cache->get($uploadKey)) {
455 1
            return $this->response->send(null, HttpResponse::HTTP_GONE);
456
        }
457
458 7
        $status = $this->verifyPatchRequest($meta);
459
460 7
        if (HttpResponse::HTTP_OK !== $status) {
461 2
            return $this->response->send(null, $status);
462
        }
463
464 5
        $file     = $this->buildFile($meta);
465 5
        $checksum = $meta['checksum'];
466
467
        try {
468 5
            $fileSize   = $file->getFileSize();
469 5
            $prevOffset = $file->getOffset();
470 5
            $offset     = $file->setKey($uploadKey)->setChecksum($checksum)->upload($fileSize);
471
472 2
            $this->event(\TusPhp\Events\Progress::class, $file, $fileSize, $prevOffset, $offset);
473
474
            // If upload is done, verify checksum and trigger event.
475 2
            if ($offset === $fileSize) {
476 1
                if ( ! $this->verifyChecksum($checksum, $meta['file_path'])) {
477 1
                    return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
478
                }
479 1
                $this->event(\TusPhp\Events\Completed::class, $file, $this->getRequest(), $this->getResponse());
480
            }
481 3
        } catch (FileException $e) {
482 1
            return $this->response->send($e->getMessage(), HttpResponse::HTTP_UNPROCESSABLE_ENTITY);
483 2
        } catch (OutOfRangeException $e) {
484 1
            return $this->response->send(null, HttpResponse::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE);
485 1
        } catch (ConnectionException $e) {
486 1
            return $this->response->send(null, HttpResponse::HTTP_CONTINUE);
487
        }
488
489 1
        return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
490 1
            'Content-Type' => 'application/offset+octet-stream',
491 1
            'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
492 1
            'Upload-Offset' => $offset,
493
        ]);
494
    }
495
496
    /**
497
     * Verify PATCH request.
498
     *
499
     * @param array $meta
500
     *
501
     * @return int
502
     */
503 7
    protected function verifyPatchRequest(array $meta) : int
504
    {
505 7
        if (self::UPLOAD_TYPE_FINAL === $meta['upload_type']) {
506 1
            return HttpResponse::HTTP_FORBIDDEN;
507
        }
508
509 6
        $uploadOffset = $this->request->header('upload-offset');
510
511 6
        if ($uploadOffset && $uploadOffset !== (string) $meta['offset']) {
512 1
            return HttpResponse::HTTP_CONFLICT;
513
        }
514
515 5
        return HttpResponse::HTTP_OK;
516
    }
517
518
    /**
519
     * Handle GET request.
520
     *
521
     * @return BinaryFileResponse|HttpResponse
522
     */
523 4
    protected function handleGet()
524
    {
525 4
        $key = $this->request->key();
526
527 4
        if ($this->request->path() === $this->getApiPath()) {
528 1
            return $this->response->send('400 bad request.', HttpResponse::HTTP_BAD_REQUEST);
529
        }
530
531 3
        if ( ! $fileMeta = $this->cache->get($key)) {
532 1
            return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND);
533
        }
534
535 2
        $resource = $fileMeta['file_path'] ?? null;
536 2
        $fileName = $fileMeta['name'] ?? null;
537
538 2
        if ( ! $resource || ! file_exists($resource)) {
539 1
            return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND);
540
        }
541
542 1
        return $this->response->download($resource, $fileName);
543
    }
544
545
    /**
546
     * Handle DELETE request.
547
     *
548
     * @return HttpResponse
549
     */
550 3
    protected function handleDelete() : HttpResponse
551
    {
552 3
        $key      = $this->request->key();
553 3
        $fileMeta = $this->cache->get($key);
554 3
        $resource = $fileMeta['file_path'] ?? null;
555
556 3
        if ( ! $resource) {
557 1
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
558
        }
559
560 2
        $isDeleted = $this->cache->delete($key);
561
562 2
        if ( ! $isDeleted || ! file_exists($resource)) {
563 1
            return $this->response->send(null, HttpResponse::HTTP_GONE);
564
        }
565
566 1
        unlink($resource);
567
568 1
        return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
569 1
            'Tus-Extension' => self::TUS_EXTENSION_TERMINATION,
570
        ]);
571
    }
572
573
    /**
574
     * Get required headers for head request.
575
     *
576
     * @param array $fileMeta
577
     *
578
     * @return array
579
     */
580 4
    protected function getHeadersForHeadRequest(array $fileMeta) : array
581
    {
582
        $headers = [
583 4
            'Upload-Length' => (int) $fileMeta['size'],
584 4
            'Upload-Offset' => (int) $fileMeta['offset'],
585 4
            'Cache-Control' => 'no-store',
586
        ];
587
588 4
        if (self::UPLOAD_TYPE_FINAL === $fileMeta['upload_type'] && $fileMeta['size'] !== $fileMeta['offset']) {
589 2
            unset($headers['Upload-Offset']);
590
        }
591
592 4
        if (self::UPLOAD_TYPE_NORMAL !== $fileMeta['upload_type']) {
593 3
            $headers += ['Upload-Concat' => $fileMeta['upload_type']];
594
        }
595
596 4
        return $headers;
597
    }
598
599
    /**
600
     * Build file object.
601
     *
602
     * @param array $meta
603
     *
604
     * @return File
605
     */
606 1
    protected function buildFile(array $meta) : File
607
    {
608 1
        $file = new File($meta['name'], $this->cache);
609
610 1
        if (array_key_exists('offset', $meta)) {
611 1
            $file->setMeta($meta['offset'], $meta['size'], $meta['file_path'], $meta['location']);
612
        }
613
614 1
        return $file;
615
    }
616
617
    /**
618
     * Get list of supported hash algorithms.
619
     *
620
     * @return string
621
     */
622 1
    protected function getSupportedHashAlgorithms() : string
623
    {
624 1
        $supportedAlgorithms = hash_algos();
625
626 1
        $algorithms = [];
627 1
        foreach ($supportedAlgorithms as $hashAlgo) {
628 1
            if (false !== strpos($hashAlgo, ',')) {
629 1
                $algorithms[] = "'{$hashAlgo}'";
630
            } else {
631 1
                $algorithms[] = $hashAlgo;
632
            }
633
        }
634
635 1
        return implode(',', $algorithms);
636
    }
637
638
    /**
639
     * Verify and get upload checksum from header.
640
     *
641
     * @return string|HttpResponse
642
     */
643 4
    protected function getClientChecksum()
644
    {
645 4
        $checksumHeader = $this->getRequest()->header('Upload-Checksum');
646
647 4
        if (empty($checksumHeader)) {
648 1
            return '';
649
        }
650
651 3
        list($checksumAlgorithm, $checksum) = explode(' ', $checksumHeader);
652
653 3
        $checksum = base64_decode($checksum);
654
655 3
        if ( ! in_array($checksumAlgorithm, hash_algos()) || false === $checksum) {
656 2
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
657
        }
658
659 1
        return $checksum;
660
    }
661
662
    /**
663
     * Get expired but incomplete uploads.
664
     *
665
     * @param array|null $contents
666
     *
667
     * @return bool
668
     */
669 3
    protected function isExpired($contents) : bool
670
    {
671 3
        $isExpired = empty($contents['expires_at']) || Carbon::parse($contents['expires_at'])->lt(Carbon::now());
672
673 3
        if ($isExpired && $contents['offset'] !== $contents['size']) {
674 3
            return true;
675
        }
676
677 2
        return false;
678
    }
679
680
    /**
681
     * Get path for partial upload.
682
     *
683
     * @param string $key
684
     *
685
     * @return string
686
     */
687 1
    protected function getPathForPartialUpload(string $key) : string
688
    {
689 1
        list($actualKey, /* $partialUploadKey */) = explode(self::PARTIAL_UPLOAD_NAME_SEPARATOR, $key);
690
691 1
        $path = $this->uploadDir . DIRECTORY_SEPARATOR . $actualKey . DIRECTORY_SEPARATOR;
692
693 1
        if ( ! file_exists($path)) {
694 1
            mkdir($path);
695
        }
696
697 1
        return $path;
698
    }
699
700
    /**
701
     * Get metadata of partials.
702
     *
703
     * @param array $partials
704
     *
705
     * @return array
706
     */
707 3
    protected function getPartialsMeta(array $partials) : array
708
    {
709 3
        $files = [];
710
711 3
        foreach ($partials as $partial) {
712 3
            $fileMeta = $this->getCache()->get($partial);
713
714 3
            $files[] = $fileMeta;
715
        }
716
717 3
        return $files;
718
    }
719
720
    /**
721
     * Delete expired resources.
722
     *
723
     * @return array
724
     */
725 2
    public function handleExpiration() : array
726
    {
727 2
        $deleted   = [];
728 2
        $cacheKeys = $this->cache->keys();
729
730 2
        foreach ($cacheKeys as $key) {
731 2
            $fileMeta = $this->cache->get($key, true);
732
733 2
            if ( ! $this->isExpired($fileMeta)) {
734 1
                continue;
735
            }
736
737 2
            if ( ! $this->cache->delete($key)) {
738 1
                continue;
739
            }
740
741 1
            if (is_writable($fileMeta['file_path'])) {
742 1
                unlink($fileMeta['file_path']);
743
            }
744
745 1
            $deleted[] = $fileMeta;
746
        }
747
748 2
        return $deleted;
749
    }
750
751
    /**
752
     * Verify max upload size.
753
     *
754
     * @return bool
755
     */
756 1
    protected function verifyUploadSize() : bool
757
    {
758 1
        $maxUploadSize = $this->getMaxUploadSize();
759
760 1
        if ($maxUploadSize > 0 && $this->getRequest()->header('Upload-Length') > $maxUploadSize) {
761 1
            return false;
762
        }
763
764 1
        return true;
765
    }
766
767
    /**
768
     * Verify checksum if available.
769
     *
770
     * @param string $checksum
771
     * @param string $filePath
772
     *
773
     * @return bool
774
     */
775 1
    protected function verifyChecksum(string $checksum, string $filePath) : bool
776
    {
777
        // Skip if checksum is empty.
778 1
        if (empty($checksum)) {
779 1
            return true;
780
        }
781
782 1
        return $checksum === $this->getServerChecksum($filePath);
783
    }
784
785
    /**
786
     * No other methods are allowed.
787
     *
788
     * @param string $method
789
     * @param array  $params
790
     *
791
     * @return HttpResponse
792
     */
793 1
    public function __call(string $method, array $params)
794
    {
795 1
        return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
796
    }
797
}
798