Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Real.php
Go to the documentation of this file.
1 <?php
8 
12 
20 {
24  private $nullable;
25 
29  private $unsigned;
30 
34  private $resourceConnection;
35 
39  private $comment;
40 
47  public function __construct(
48  Nullable $nullable,
49  Unsigned $unsigned,
50  Comment $comment,
51  ResourceConnection $resourceConnection
52  ) {
53  $this->nullable = $nullable;
54  $this->unsigned = $unsigned;
55  $this->resourceConnection = $resourceConnection;
56  $this->comment = $comment;
57  }
58 
63  public function toDefinition(ElementInterface $column)
64  {
65  if ($column->getPrecision() === 0 && $column->getScale() === 0) {
66  $type = $column->getType();
67  } else {
68  $type = sprintf('%s(%s, %s)', $column->getType(), $column->getPrecision(), $column->getScale());
69  }
70 
71  return sprintf(
72  '%s %s %s %s %s %s',
73  $this->resourceConnection->getConnection()->quoteIdentifier($column->getName()),
74  $type,
75  $this->unsigned->toDefinition($column),
76  $this->nullable->toDefinition($column),
77  $column->getDefault() !== null ?
78  sprintf('DEFAULT %s', $column->getDefault()) : '',
79  $this->comment->toDefinition($column)
80  );
81  }
82 
86  public function fromDefinition(array $data)
87  {
88  $matches = [];
89  if (preg_match('/^(float|decimal|double)\s*\((\d+)\s*,\s*(\d+)\)/i', $data['definition'], $matches)) {
95  $data['precision'] = $matches[2];
96  $data['scale'] = $matches[3];
97  $data = $this->nullable->fromDefinition($data);
98  $data = $this->unsigned->fromDefinition($data);
99  } elseif (preg_match('/^decimal\s*\(\s*(\d+)\s*\)/i', $data['definition'], $matches)) {
100  $data['precision'] = $matches[1];
101  $data['scale'] = 0;
102  }
103 
104  return $data;
105  }
106 }
__construct(Nullable $nullable, Unsigned $unsigned, Comment $comment, ResourceConnection $resourceConnection)
Definition: Real.php:47
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13