ILIAS  release_8 Revision v8.24
BlacklistFileHeaderPreProcessor.php
Go to the documentation of this file.
1<?php
2
4
8use ILIAS\FileUpload\ScalarTypeCheckAware;
9use Psr\Http\Message\StreamInterface;
10
11/******************************************************************************
12 *
13 * This file is part of ILIAS, a powerful learning management system.
14 *
15 * ILIAS is licensed with the GPL-3.0, you should have received a copy
16 * of said license along with the source code.
17 *
18 * If this is not the case or you just want to try ILIAS, you'll find
19 * us at:
20 * https://www.ilias.de
21 * https://github.com/ILIAS-eLearning
22 *
23 *****************************************************************************/
34{
35 use ScalarTypeCheckAware;
36
37 private string $fileHeader;
38 private int $fileHeaderLength;
39
40
44 public function __construct(string $fileHeader)
45 {
46 $this->stringTypeCheck($fileHeader, 'fileHeader');
47
48 $this->fileHeaderLength = strlen($fileHeader);
49 $this->fileHeader = $fileHeader;
50 }
51
52
56 public function process(FileStream $stream, Metadata $metadata): ProcessingStatus
57 {
58 $header = $stream->read($this->fileHeaderLength);
59 if (strcmp($this->fileHeader, $header) !== 0) {
60 return new ProcessingStatus(ProcessingStatus::OK, 'File header does not match blacklist.');
61 }
62
63 return new ProcessingStatus(ProcessingStatus::REJECTED, 'File header matches blacklist.');
64 }
65}
const REJECTED
Upload got rejected by a processor.
process(FileStream $stream, Metadata $metadata)
@inheritDoc
__construct(string $fileHeader)
BlacklistFileHeaderPreProcessor constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...