Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AstConverter.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use GraphQL\Language\AST\ListValueNode;
11 use GraphQL\Language\AST\NodeList;
15 
20 {
24  private $clauseFactory;
25 
29  private $connectiveFactory;
30 
34  private $fieldEntityAttributesPool;
35 
41  public function __construct(
42  ClauseFactory $clauseFactory,
43  ConnectiveFactory $connectiveFactory,
44  FieldEntityAttributesPool $fieldEntityAttributesPool
45  ) {
46  $this->clauseFactory = $clauseFactory;
47  $this->connectiveFactory = $connectiveFactory;
48  $this->fieldEntityAttributesPool = $fieldEntityAttributesPool;
49  }
50 
58  public function getClausesFromAst(string $fieldName, array $arguments) : array
59  {
60  $attributes = $this->fieldEntityAttributesPool->getEntityAttributesForEntityFromField($fieldName);
61  $conditions = [];
62  foreach ($arguments as $argumentName => $argument) {
63  if (in_array($argumentName, $attributes)) {
64  foreach ($argument as $clauseType => $clause) {
65  if (is_array($clause)) {
66  $value = [];
67  foreach ($clause as $item) {
68  $value[] = $item;
69  }
70  } else {
71  $value = $clause;
72  }
73  $conditions[] = $this->clauseFactory->create(
74  $argumentName,
75  $clauseType,
76  $value
77  );
78  }
79  } else {
80  $conditions[] =
81  $this->connectiveFactory->create(
82  $this->getClausesFromAst($fieldName, $argument),
83  $argumentName
84  );
85  }
86  }
87  return $conditions;
88  }
89 }
__construct(ClauseFactory $clauseFactory, ConnectiveFactory $connectiveFactory, FieldEntityAttributesPool $fieldEntityAttributesPool)
$value
Definition: gender.phtml:16
$attributes
Definition: matrix.phtml:13
$arguments
getClausesFromAst(string $fieldName, array $arguments)