FileInfoArray.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Gedmo\Uploadable\FileInfo;
  3. /**
  4. * FileInfoArray
  5. *
  6. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  7. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  8. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  9. */
  10. class FileInfoArray implements FileInfoInterface
  11. {
  12. protected $fileInfo;
  13. public function __construct(array $fileInfo)
  14. {
  15. $keys = array('error', 'size', 'type', 'tmp_name', 'name');
  16. foreach ($keys as $k) {
  17. if (!isset($fileInfo[$k])) {
  18. $msg = 'There are missing keys in the fileInfo. ';
  19. $msg .= 'Keys needed: '.implode(',', $keys);
  20. throw new \RuntimeException($msg);
  21. }
  22. }
  23. $this->fileInfo = $fileInfo;
  24. }
  25. public function getTmpName()
  26. {
  27. return $this->fileInfo['tmp_name'];
  28. }
  29. public function getName()
  30. {
  31. return $this->fileInfo['name'];
  32. }
  33. public function getSize()
  34. {
  35. return $this->fileInfo['size'];
  36. }
  37. public function getType()
  38. {
  39. return $this->fileInfo['type'];
  40. }
  41. public function getError()
  42. {
  43. return $this->fileInfo['error'];
  44. }
  45. public function isUploadedFile()
  46. {
  47. return true;
  48. }
  49. }