Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / InsertEditColumn.php
blob8d42b0e0c288510c560f4673da17d215588f7961
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin;
7 use function date;
8 use function md5;
9 use function preg_match;
10 use function preg_replace;
12 final class InsertEditColumn
14 public readonly string|null $default;
15 public readonly string $md5;
16 /**
17 * trueType contains only the type (stops at first bracket)
19 public readonly string $trueType;
20 public readonly string $pmaType;
21 public readonly int $length;
22 public readonly bool $firstTimestamp;
24 public function __construct(
25 public readonly string $field,
26 public readonly string $type,
27 public readonly bool $isNull,
28 public readonly string $key,
29 string|null $default,
30 public readonly string $extra,
31 int $columnLength,
32 public readonly bool $isBinary,
33 public readonly bool $isBlob,
34 public readonly bool $isChar,
35 bool $insertMode,
36 ) {
37 if (
38 $this->type === 'datetime'
39 && ! $this->isNull
40 && $default === null
41 && $insertMode
42 ) {
43 $this->default = date('Y-m-d H:i:s');
44 } else {
45 $this->default = $default;
48 $this->md5 = md5($this->field);
49 $this->trueType = preg_replace('@\(.*@s', '', $this->type);
50 // length is unknown for geometry fields,
51 // make enough space to edit very simple WKTs
52 if ($columnLength === -1) {
53 $columnLength = 30;
56 $this->length = preg_match('@float|double@', $this->type) ? 100 : $columnLength;
57 $this->pmaType = match ($this->trueType) {
58 'set', 'enum' => $this->trueType,
59 default => $this->type,
61 /**
62 * TODO: This property is useless at the moment.
63 * It seems like a long time ago before refactoring into classes,
64 * this kept track of how many timestamps are in the table.
66 $this->firstTimestamp = $this->trueType === 'timestamp';