Currency.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\DirectoryGraphQl\Model\Resolver;
  8. use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
  9. use Magento\Framework\GraphQl\Config\Element\Field;
  10. use Magento\Framework\GraphQl\Query\ResolverInterface;
  11. use Magento\Framework\Reflection\DataObjectProcessor;
  12. use Magento\Directory\Api\CurrencyInformationAcquirerInterface;
  13. use Magento\Directory\Api\Data\CurrencyInformationInterface;
  14. /**
  15. * Currency field resolver, used for GraphQL request processing.
  16. */
  17. class Currency implements ResolverInterface
  18. {
  19. /**
  20. * @var DataObjectProcessor
  21. */
  22. private $dataProcessor;
  23. /**
  24. * @var CurrencyInformationAcquirerInterface
  25. */
  26. private $currencyInformationAcquirer;
  27. /**
  28. * @param DataObjectProcessor $dataProcessor
  29. * @param CurrencyInformationAcquirerInterface $currencyInformationAcquirer
  30. */
  31. public function __construct(
  32. DataObjectProcessor $dataProcessor,
  33. CurrencyInformationAcquirerInterface $currencyInformationAcquirer
  34. ) {
  35. $this->dataProcessor = $dataProcessor;
  36. $this->currencyInformationAcquirer = $currencyInformationAcquirer;
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function resolve(
  42. Field $field,
  43. $context,
  44. ResolveInfo $info,
  45. array $value = null,
  46. array $args = null
  47. ) {
  48. return $this->dataProcessor->buildOutputDataArray(
  49. $this->currencyInformationAcquirer->getCurrencyInfo(),
  50. CurrencyInformationInterface::class
  51. );
  52. }
  53. }