Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RealDefinition.php
Go to the documentation of this file.
1 <?php
8 
13 {
19  private static $shapeByType = [
20  'float' => [
21  'precision' => '0',
22  'scale' => '0'
23  ],
24  'decimal' => [
25  'precision' => '0',
26  'scale' => '10'
27  ],
28  'double' => [
29  'precision' => '0',
30  'scale' => '0'
31  ]
32  ];
33 
37  public function convertToDefinition(array $definition)
38  {
39  if (isset($definition['length'])) {
40  list($definition['precision'], $definition['scale']) = explode(",", $definition['length']);
41  }
42  return [
43  'xsi:type' => $definition['type'],
44  'name' => $definition['name'],
45  //In previous adapter this 2 fields were switched, so we need to switch again
46  'scale' => $definition['scale'] ?? self::$shapeByType[$definition['type']]['scale'],
47  'precision' => $definition['precision'] ?? self::$shapeByType[$definition['type']]['precision'],
48  'unsigned' => $definition['unsigned'] ?? false,
49  'nullable' => $definition['nullable'] ?? true,
50  'default' => isset($definition['default']) && $definition['default'] !== false ?
51  (int) $definition['default'] : null,
52  'primary' => $definition['primary'] ?? false
53  ];
54  }
55 }