Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeTypeResolver.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
17  protected $config;
18 
22  protected $typeProcessor;
23 
29  {
30  $this->config = $config;
31  $this->typeProcessor = $typeProcessor;
32  }
33 
37  public function resolveObjectType($attributeCode, $value, $context)
38  {
39  if (!is_object($value)) {
40  throw new \InvalidArgumentException('Provided value is not object type');
41  }
42  $data = $this->config->get();
43  $context = trim($context, '\\');
44  $config = isset($data[$context]) ? $data[$context] : [];
45  $output = get_class($value);
46  if (isset($config[$attributeCode])) {
47  $type = $config[$attributeCode]['type'];
48  $output = $this->typeProcessor->getArrayItemType($type);
49  if (!(class_exists($output) || interface_exists($output))) {
50  throw new \LogicException(
51  sprintf(
52  'The "%s" class doesn\'t exist and the namespace must be specified. Verify and try again.',
53  $type
54  )
55  );
56  }
57  }
58  return $output;
59  }
60 }
$type
Definition: item.phtml:13
__construct(TypeProcessor $typeProcessor, Config $config)
$value
Definition: gender.phtml:16
$attributeCode
Definition: extend.phtml:12