Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractDataAssignObserver.php
Go to the documentation of this file.
1 <?php
7 
13 
21 {
22  const METHOD_CODE = 'method';
23 
24  const DATA_CODE = 'data';
25 
26  const MODEL_CODE = 'payment_model';
27 
35  {
36  return $this->readArgument($observer, static::METHOD_CODE, MethodInterface::class);
37  }
38 
47  {
48  return $this->readArgument($observer, static::MODEL_CODE, InfoInterface::class);
49  }
50 
57  protected function readDataArgument(Observer $observer)
58  {
59  return $this->readArgument($observer, static::DATA_CODE, DataObject::class);
60  }
61 
71  protected function readArgument(Observer $observer, $key, $type)
72  {
73  $event = $observer->getEvent();
74  $argument = $event->getDataByKey($key);
75 
76  if (!$argument instanceof $type) {
77  throw new \LogicException('Wrong argument type provided.');
78  }
79 
80  return $argument;
81  }
82 }
$type
Definition: item.phtml:13