JsonConverter.php 899 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Serialize;
  7. /**
  8. * This class was introducted only for usage in the \Magento\Framework\DataObject::toJson method.
  9. * It should not be used in other cases and instead \Magento\Framework\Serialize\Serializer\Json::serialize
  10. * should be used.
  11. */
  12. class JsonConverter
  13. {
  14. /**
  15. * This method should only be used by \Magento\Framework\DataObject::toJson
  16. * All other cases should use \Magento\Framework\Serialize\Serializer\Json::serialize directly
  17. *
  18. * @param string|int|float|bool|array|null $data
  19. * @return bool|string
  20. * @throws \InvalidArgumentException
  21. */
  22. public static function convert($data)
  23. {
  24. $serializer = new \Magento\Framework\Serialize\Serializer\Json();
  25. return $serializer->serialize($data);
  26. }
  27. }