ArgumentFactory.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. * {@inheritdoc}
  11. */
  12. class ArgumentFactory
  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 argument object based off a configured Output/InputInterface's data.
  28. *
  29. * Argument data must contain name and type. Other values are optional and include baseType, itemType, description,
  30. * required, and itemsRequired.
  31. *
  32. * @param array $argumentData
  33. * @return Argument
  34. */
  35. public function createFromConfigData(
  36. array $argumentData
  37. ) : Argument {
  38. return $this->objectManager->create(
  39. Argument::class,
  40. [
  41. 'name' => $argumentData['name'],
  42. 'type' => isset($argumentData['itemType']) ? $argumentData['itemType'] : $argumentData['type'],
  43. 'baseType' => isset($argumentData['baseType']) ? $argumentData['baseType'] : '',
  44. 'description' => isset($argumentData['description']) ? $argumentData['description'] : '',
  45. 'required' => isset($argumentData['required']) ? $argumentData['required'] : false,
  46. 'isList' => isset($argumentData['itemType']),
  47. 'itemType' => isset($argumentData['itemType']) ? $argumentData['itemType'] : '',
  48. 'itemsRequired' => isset($argumentData['itemsRequired']) ? $argumentData['itemsRequired'] : false,
  49. 'defaultValue' => isset($argumentData['defaultValue']) ? $argumentData['defaultValue'] : null
  50. ]
  51. );
  52. }
  53. }