ValueFactory.php 918 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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\Framework\GraphQl\Query\Resolver;
  8. use Magento\Framework\ObjectManagerInterface;
  9. /**
  10. * Create @see Value to return data from passed in callback to GraphQL library
  11. */
  12. class ValueFactory
  13. {
  14. /**
  15. * @var ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. /**
  19. * @param ObjectManagerInterface $objectManager
  20. */
  21. public function __construct(ObjectManagerInterface $objectManager)
  22. {
  23. $this->objectManager = $objectManager;
  24. }
  25. /**
  26. * Create value with passed in callback that returns data as parameter;
  27. *
  28. * @param callable $callback
  29. * @return Value
  30. */
  31. public function create(callable $callback)
  32. {
  33. return $this->objectManager->create(Value::class, ['callback' => $callback]);
  34. }
  35. }