Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValueChecker.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
16  protected $fallbackResolver;
17 
21  protected $appConfig;
22 
26  protected $valueProcessor;
27 
33  public function __construct(
37  ) {
38  $this->fallbackResolver = $fallbackResolver;
39  $this->appConfig = $appConfig;
40  $this->valueProcessor = $valueProcessor;
41  }
42 
52  public function isDifferentFromDefault($value, $scope, $scopeId, array $fieldConfig)
53  {
54  list($scope, $scopeId) = $this->fallbackResolver->getFallbackScope($scope, $scopeId);
55  if ($scope) {
56  return !$this->isEqual(
57  $this->valueProcessor->process(
58  $value,
59  $scope,
60  $scopeId,
61  $fieldConfig
62  ),
63  $this->valueProcessor->process(
64  $this->appConfig->getValue($fieldConfig['path'], $scope, $scopeId),
65  $scope,
66  $scopeId,
67  $fieldConfig
68  )
69  );
70  }
71  return true;
72  }
73 
81  protected function isEqual($value, $defaultValue)
82  {
83  switch (gettype($value)) {
84  case 'array':
85  return $this->isEqualArrays($value, $defaultValue);
86  default:
87  return $value === $defaultValue;
88  }
89  }
90 
98  protected function isEqualArrays(array $value, array $defaultValue)
99  {
100  $result = true;
101  if (count($value) !== count($defaultValue)) {
102  return false;
103  }
104  foreach ($value as $key => $elem) {
105  if (is_array($elem)) {
106  if (isset($defaultValue[$key])) {
107  $result = $result && $this->isEqualArrays($elem, $defaultValue[$key]);
108  } else {
109  return false;
110  }
111  } else {
112  if (isset($defaultValue[$key])) {
113  $result = $result && ($defaultValue[$key] == $elem);
114  } else {
115  return false;
116  }
117  }
118  }
119  return $result;
120  }
121 }
isEqualArrays(array $value, array $defaultValue)
$value
Definition: gender.phtml:16
__construct(ScopeFallbackResolverInterface $fallbackResolver, AppConfig $appConfig, ValueProcessor $valueProcessor)
isDifferentFromDefault($value, $scope, $scopeId, array $fieldConfig)