summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/file/src/Upload/FormUploadedFile.php
blob: f4bd4ac4b8b6101cd9f557e136dda20d3e49456d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

namespace Drupal\file\Upload;

use Drupal\file\Validation\Constraint\UploadedFileConstraint;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

/**
 * Provides a bridge to Symfony UploadedFile.
 */
class FormUploadedFile implements UploadedFileInterface {

  /**
   * The wrapped uploaded file.
   *
   * @var \Symfony\Component\HttpFoundation\File\UploadedFile
   */
  protected $uploadedFile;

  /**
   * Creates a new FormUploadedFile.
   *
   * @param \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
   *   The wrapped Symfony uploaded file.
   */
  public function __construct(UploadedFile $uploadedFile) {
    $this->uploadedFile = $uploadedFile;
  }

  /**
   * {@inheritdoc}
   */
  public function getClientOriginalName(): string {
    return $this->uploadedFile->getClientOriginalName();
  }

  /**
   * {@inheritdoc}
   */
  public function getSize(): int {
    return $this->uploadedFile->getSize();
  }

  /**
   * {@inheritdoc}
   */
  public function getRealPath() {
    return $this->uploadedFile->getRealPath();
  }

  /**
   * {@inheritdoc}
   */
  public function getPathname(): string {
    return $this->uploadedFile->getPathname();
  }

  /**
   * {@inheritdoc}
   */
  public function getFilename(): string {
    return $this->uploadedFile->getFilename();
  }

  /**
   * {@inheritdoc}
   */
  public function validate(ValidatorInterface $validator, array $options = []): ConstraintViolationListInterface {
    $constraint = new UploadedFileConstraint($options);
    return $validator->validate($this->uploadedFile, $constraint);
  }

}