FileInfoArray.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * @package Gedmo.Uploadable.FileInfo
  9. * @subpackage FileInfoArray
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class FileInfoArray implements FileInfoInterface
  14. {
  15. protected $fileInfo;
  16. public function __construct(array $fileInfo)
  17. {
  18. $keys = array('error', 'size', 'type', 'tmp_name', 'name');
  19. foreach ($keys as $k) {
  20. if (!isset($fileInfo[$k])) {
  21. $msg = 'There are missing keys in the fileInfo. ';
  22. $msg .= 'Keys needed: '.implode(',', $keys);
  23. throw new \RuntimeException($msg);
  24. }
  25. }
  26. $this->fileInfo = $fileInfo;
  27. }
  28. public function getTmpName()
  29. {
  30. return $this->fileInfo['tmp_name'];
  31. }
  32. public function getName()
  33. {
  34. return $this->fileInfo['name'];
  35. }
  36. public function getSize()
  37. {
  38. return $this->fileInfo['size'];
  39. }
  40. public function getType()
  41. {
  42. return $this->fileInfo['type'];
  43. }
  44. public function getError()
  45. {
  46. return $this->fileInfo['error'];
  47. }
  48. public function isUploadedFile()
  49. {
  50. return true;
  51. }
  52. }