UploadedFile.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
  11. use Psr\Http\Message\UploadedFileInterface;
  12. /**
  13. * @author Kévin Dunglas <dunglas@gmail.com>
  14. */
  15. class UploadedFile implements UploadedFileInterface
  16. {
  17. private $filePath;
  18. private $size;
  19. private $error;
  20. private $clientFileName;
  21. private $clientMediaType;
  22. public function __construct($filePath, $size = null, $error = \UPLOAD_ERR_OK, $clientFileName = null, $clientMediaType = null)
  23. {
  24. $this->filePath = $filePath;
  25. $this->size = $size;
  26. $this->error = $error;
  27. $this->clientFileName = $clientFileName;
  28. $this->clientMediaType = $clientMediaType;
  29. }
  30. public function getStream(): Stream
  31. {
  32. return new Stream(file_get_contents($this->filePath));
  33. }
  34. public function moveTo($targetPath): void
  35. {
  36. rename($this->filePath, $targetPath);
  37. }
  38. public function getSize(): ?int
  39. {
  40. return $this->size;
  41. }
  42. public function getError(): int
  43. {
  44. return $this->error;
  45. }
  46. public function getClientFilename(): ?string
  47. {
  48. return $this->clientFileName;
  49. }
  50. public function getClientMediaType(): ?string
  51. {
  52. return $this->clientMediaType;
  53. }
  54. }