EnumValueFactory.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Config\Element;
  8. use Magento\Framework\ObjectManagerInterface;
  9. /**
  10. * Factory for config elements of 'enum value' type.
  11. */
  12. class EnumValueFactory
  13. {
  14. /**
  15. * @var ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. /**
  19. * @param ObjectManagerInterface $objectManager
  20. */
  21. public function __construct(
  22. ObjectManagerInterface $objectManager
  23. ) {
  24. $this->objectManager = $objectManager;
  25. }
  26. /**
  27. * Create an enum value object based off a configured EnumType's data. Name and value required.
  28. *
  29. * @param string $name
  30. * @param string $value
  31. * @param string $description
  32. * @return EnumValue
  33. */
  34. public function create(string $name, string $value, string $description = ''): EnumValue
  35. {
  36. return $this->objectManager->create(
  37. EnumValue::class,
  38. [
  39. 'name' => $name,
  40. 'value' => $value,
  41. 'description' => $description
  42. ]
  43. );
  44. }
  45. }