RequestData.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Model\Config\Backend\File;
  7. class RequestData implements \Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface
  8. {
  9. /**
  10. * Retrieve uploaded file tmp name by path
  11. *
  12. * @param string $path
  13. * @return string
  14. */
  15. public function getTmpName($path)
  16. {
  17. return $this->_getParam('tmp_name', $path);
  18. }
  19. /**
  20. * Retrieve uploaded file name by path
  21. *
  22. * @param string $path
  23. * @return string
  24. */
  25. public function getName($path)
  26. {
  27. return $this->_getParam('name', $path);
  28. }
  29. /**
  30. * Get $_FILES superglobal value by path
  31. *
  32. * @param string $paramName
  33. * @param string $path
  34. * @return string
  35. */
  36. protected function _getParam($paramName, $path)
  37. {
  38. $pathParts = explode('/', $path);
  39. array_shift($pathParts);
  40. $fieldId = array_pop($pathParts);
  41. $firstGroupId = array_shift($pathParts);
  42. if (!isset($_FILES['groups'][$paramName])) {
  43. return null;
  44. }
  45. $groupData = $_FILES['groups'][$paramName];
  46. if (isset($groupData[$firstGroupId])) {
  47. $groupData = $groupData[$firstGroupId];
  48. }
  49. foreach ($pathParts as $groupId) {
  50. if (isset($groupData['groups'][$groupId])) {
  51. $groupData = $groupData['groups'][$groupId];
  52. } else {
  53. return null;
  54. }
  55. }
  56. if (isset($groupData['fields'][$fieldId]['value'])) {
  57. return $groupData['fields'][$fieldId]['value'];
  58. }
  59. return null;
  60. }
  61. }