ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
WhitelistFileHeaderPreProcessor.php
Go to the documentation of this file.
1 <?php
2 
4 
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 {
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 complies with whitelist.');
61  }
62 
63  return new ProcessingStatus(ProcessingStatus::REJECTED, 'File header don\'t complies with whitelist.');
64  }
65 }
const REJECTED
Upload got rejected by a processor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $fileHeader)
WhitelistFileHeaderPreProcessor constructor.
Interface FileStream.
Definition: FileStream.php:33