FieldEntityAttributesPool.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\Argument;
  8. /**
  9. * Retrieves attributes for a field for the ast converter
  10. */
  11. class FieldEntityAttributesPool
  12. {
  13. /**
  14. * @var FieldEntityAttributesInterface[]
  15. */
  16. private $attributesInstances = [];
  17. /**
  18. * @param FieldEntityAttributesInterface[] $attributesInstances
  19. */
  20. public function __construct(
  21. array $attributesInstances = []
  22. ) {
  23. $this->attributesInstances = $attributesInstances;
  24. }
  25. /**
  26. * Get the attributes that can be filtered for based on the graphql field name that represents an entity
  27. *
  28. * @param string $fieldName
  29. * @return array
  30. * @throws \LogicException
  31. */
  32. public function getEntityAttributesForEntityFromField(string $fieldName) : array
  33. {
  34. if (isset($this->attributesInstances[$fieldName])) {
  35. return $this->attributesInstances[$fieldName]->getEntityAttributes();
  36. } else {
  37. throw new \LogicException(sprintf('There is no attribute class assigned to field %1', $fieldName));
  38. }
  39. }
  40. }