Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / upload / MediaUploadFileValidationStrategy.class.php
1 <?php
2
3 namespace wcf\system\upload;
4
5 /**
6 * Upload file validation strategy implementation for media files.
7 *
8 * @author Matthias Schmidt
9 * @copyright 2001-2019 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package WoltLabSuite\Core\System\Upload
12 * @since 3.0
13 */
14 class MediaUploadFileValidationStrategy implements IUploadFileValidationStrategy
15 {
16 /**
17 * if `true`, only images are valid
18 * @var bool
19 */
20 protected $imagesOnly = false;
21
22 /**
23 * Creates a new instance of MediaUploadFileValidationStrategy.
24 *
25 * @param bool $imagesOnly
26 */
27 public function __construct($imagesOnly)
28 {
29 $this->imagesOnly = $imagesOnly;
30 }
31
32 /**
33 * @inheritDoc
34 */
35 public function validate(UploadFile $uploadFile)
36 {
37 if ($uploadFile->getErrorCode()) {
38 $uploadFile->setValidationErrorType('uploadFailed');
39
40 return false;
41 }
42
43 if ($this->imagesOnly && $uploadFile->getImageData() === null) {
44 $uploadFile->setValidationErrorType('noImage');
45
46 return false;
47 }
48
49 return true;
50 }
51 }