Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InputMapper.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
17 {
21  private $inputFactory;
22 
26  private $config;
27 
31  private $typeFactory;
32 
36  private $scalarTypes;
37 
41  private $wrappedTypeProcessor;
42 
50  public function __construct(
51  InputFactory $inputFactory,
52  ConfigInterface $config,
53  TypeFactory $typeFactory,
54  ScalarTypes $scalarTypes,
55  WrappedTypeProcessor $wrappedTypeProcessor
56  ) {
57  $this->inputFactory = $inputFactory;
58  $this->config = $config;
59  $this->typeFactory = $typeFactory;
60  $this->scalarTypes = $scalarTypes;
61  $this->wrappedTypeProcessor = $wrappedTypeProcessor;
62  }
63 
70  public function getRepresentation(Argument $argument) : array
71  {
72  $typeName = $argument->getTypeName();
73  if ($this->scalarTypes->isScalarType($typeName)) {
74  $instance = $this->wrappedTypeProcessor->processScalarWrappedType($argument);
75  } else {
76  $configElement = $this->config->getConfigElement($typeName);
77  $instance = $this->inputFactory->create($configElement);
78  $instance = $this->wrappedTypeProcessor->processWrappedType($argument, $instance);
79  }
80 
81  $calculatedArgument = [
82  'type' => $instance,
83  'description' => $argument->getDescription()
84  ];
85 
86  if ($this->scalarTypes->isScalarType($typeName) && $argument->hasDefaultValue()) {
87  switch ($argument->getTypeName()) {
88  case 'Int':
89  $calculatedArgument['defaultValue'] = (int)$argument->getDefaultValue();
90  break;
91  case 'Float':
92  $calculatedArgument['defaultValue'] = (float)$argument->getDefaultValue();
93  break;
94  case 'Boolean':
95  $calculatedArgument['defaultValue'] = (bool)$argument->getDefaultValue();
96  break;
97  default:
98  $calculatedArgument['defaultValue'] = $argument->getDefaultValue();
99  }
100  }
101 
102  return $calculatedArgument;
103  }
104 }
$config
Definition: fraud_order.php:17
__construct(InputFactory $inputFactory, ConfigInterface $config, TypeFactory $typeFactory, ScalarTypes $scalarTypes, WrappedTypeProcessor $wrappedTypeProcessor)
Definition: InputMapper.php:50