ObjectConverter.php 776 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\ApiClient;
  7. use Magento\Framework\Exception\LocalizedException;
  8. /**
  9. * Converts PHP objects into an associative array
  10. */
  11. class ObjectConverter
  12. {
  13. /**
  14. * Convert an object to an associative array
  15. *
  16. * @param object $object
  17. * @return array
  18. * @throws LocalizedException
  19. */
  20. public function convertToArray($object)
  21. {
  22. $result = json_decode(json_encode($object), true);
  23. if ($result === false || $result === null) {
  24. throw new LocalizedException(__('Could not convert object to array'));
  25. }
  26. return $result;
  27. }
  28. }