Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Binder.php
Go to the documentation of this file.
1 <?php
7 
12 class Binder
13 {
21  public function bind(array $requestData, array $bindData)
22  {
23  $data = $this->processLimits($requestData, $bindData);
24  $data['dimensions'] = $this->processDimensions($requestData['dimensions'], $bindData['dimensions']);
25  $data['queries'] = $this->processData($requestData['queries'], $bindData['placeholder']);
26  $data['filters'] = $this->processData($requestData['filters'], $bindData['placeholder']);
27  $data['aggregations'] = $this->processData($requestData['aggregations'], $bindData['placeholder']);
28 
29  return $data;
30  }
31 
39  private function processLimits($data, $bindData)
40  {
41  $limitList = ['from', 'size'];
42  foreach ($limitList as $limit) {
43  if (isset($bindData[$limit])) {
44  $data[$limit] = $bindData[$limit];
45  }
46  }
47 
48  return $data;
49  }
50 
57  private function processDimensions($data, $bindData)
58  {
59  foreach ($data as $name => $value) {
60  if (isset($bindData[$name])) {
61  $data[$name]['value'] = $bindData[$name];
62  }
63  }
64 
65  return $data;
66  }
67 
75  private function processData($data, $bindData)
76  {
77  array_walk_recursive($bindData, function (&$item) {
78  $item = trim($item);
79  });
80  $bindData = array_filter($bindData, function ($element) {
81  return is_array($element) ? count($element) : strlen($element);
82  });
83 
84  foreach ($data as $key => $value) {
85  if (is_array($value)) {
86  $data[$key] = $this->processData($value, $bindData);
87  } else {
88  foreach ($bindData as $bindKey => $bindValue) {
89  if (strpos($value, $bindKey) !== false) {
90  if (is_string($bindValue)) {
91  $data[$key] = str_replace($bindKey, $bindValue, $value);
92  } else {
93  $data[$key] = $bindValue;
94  }
95  $data['is_bind'] = true;
96  }
97  }
98  }
99  }
100 
101  return $data;
102  }
103 }
$value
Definition: gender.phtml:16
bind(array $requestData, array $bindData)
Definition: Binder.php:21
$element
Definition: element.phtml:12