Js.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Adminhtml JavaScript helper
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Backend\Helper;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Js
  17. {
  18. /**
  19. * Decode serialized grid data
  20. *
  21. * Ignores non-numeric array keys
  22. *
  23. * '1&2&3&4' will be decoded into:
  24. * array(1, 2, 3, 4);
  25. *
  26. * otherwise the following format is anticipated:
  27. * 1=<encoded string>&2=<encoded string>:
  28. * array (
  29. * 1 => array(...),
  30. * 2 => array(...),
  31. * )
  32. *
  33. * @param string $encoded
  34. * @return array
  35. */
  36. public function decodeGridSerializedInput($encoded)
  37. {
  38. $isSimplified = false === strpos($encoded, '=');
  39. $result = [];
  40. parse_str($encoded, $decoded);
  41. foreach ($decoded as $key => $value) {
  42. if (is_numeric($key)) {
  43. if ($isSimplified) {
  44. $result[] = $key;
  45. } else {
  46. $result[$key] = null;
  47. parse_str(base64_decode($value), $result[$key]);
  48. }
  49. }
  50. }
  51. return $result;
  52. }
  53. }