Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
18 class Config implements ConfigInterface
19 {
23  private $configData;
24 
28  private $configElementFactory;
29 
33  private $queryFields;
34 
40  public function __construct(
42  ConfigElementFactoryInterface $configElementFactory,
43  QueryFields $queryFields
44  ) {
45  $this->configData = $data;
46  $this->configElementFactory = $configElementFactory;
47  $this->queryFields = $queryFields;
48  }
49 
58  public function getConfigElement(string $configElementName) : ConfigElementInterface
59  {
60  $data = $this->configData->get($configElementName);
61  if (!isset($data['type'])) {
62  throw new \LogicException(
63  sprintf('Config element "%s" is not declared in GraphQL schema', $configElementName)
64  );
65  }
66 
67  $fieldsInQuery = $this->queryFields->getFieldsUsedInQuery();
68  if (isset($data['fields']) && !empty($fieldsInQuery)) {
69  foreach ($data['fields'] as $fieldName => $fieldConfig) {
70  if (!isset($fieldsInQuery[$fieldName])) {
71  unset($data['fields'][$fieldName]);
72  }
73  }
74  }
75 
76  return $this->configElementFactory->createFromConfigData($data);
77  }
78 
84  public function getDeclaredTypeNames() : array
85  {
86  $types = [];
87  foreach ($this->configData->get(null) as $item) {
88  if (isset($item['type']) && $item['type'] == 'graphql_type') {
89  $types[] = $item['name'];
90  }
91  }
92  return $types;
93  }
94 }
__construct(DataInterface $data, ConfigElementFactoryInterface $configElementFactory, QueryFields $queryFields)
Definition: Config.php:40
getConfigElement(string $configElementName)
Definition: Config.php:58