1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sco\Admin\Form\Elements; |
4
|
|
|
|
5
|
|
|
use DB; |
6
|
|
|
use Doctrine\DBAL\Schema\Column; |
7
|
|
|
use Doctrine\DBAL\Types\Type; |
8
|
|
|
|
9
|
|
|
class Input extends NamedElement |
10
|
|
|
{ |
11
|
|
|
protected $maxLength; |
12
|
|
|
protected $minLength = 0; |
13
|
|
|
|
14
|
|
|
protected $size = ''; |
15
|
|
|
|
16
|
|
|
protected $readonly = false; |
17
|
|
|
|
18
|
|
|
public function getSize() |
19
|
|
|
{ |
20
|
|
|
return $this->size; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function setSize($value) |
24
|
|
|
{ |
25
|
|
|
$this->size = $value; |
26
|
|
|
|
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function mediumSize() |
31
|
|
|
{ |
32
|
|
|
return $this->setSize('medium'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function smallSize() |
36
|
|
|
{ |
37
|
|
|
return $this->setSize('small'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function miniSize() |
41
|
|
|
{ |
42
|
|
|
return $this->setSize('mini'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getModelFieldLength() |
46
|
|
|
{ |
47
|
|
|
$column = $this->getModelColumn(); |
48
|
|
|
if ($column instanceof Column && $column->getType()->getName() == Type::STRING) { |
|
|
|
|
49
|
|
|
return $column->getLength(); |
50
|
|
|
} |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return \Doctrine\DBAL\Schema\Column |
56
|
|
|
*/ |
57
|
|
|
protected function getModelColumn() |
58
|
|
|
{ |
59
|
|
|
// Doctrine\DBAL\Platforms\MySQL57Platform not support "enum" "string" |
60
|
|
|
$schema = DB::getDoctrineSchemaManager(); |
61
|
|
|
$databasePlatform = $schema->getDatabasePlatform(); |
62
|
|
|
$databasePlatform->registerDoctrineTypeMapping('enum', 'string'); |
63
|
|
|
|
64
|
|
|
$table = DB::getTablePrefix() . $this->getModel()->getTable(); |
65
|
|
|
$column = $this->getName(); |
66
|
|
|
if ($column) { |
67
|
|
|
$columns = $schema->listTableDetails($table); |
68
|
|
|
if ($columns->hasColumn($column)) { |
69
|
|
|
return $columns->getColumn($column); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getMaxLength() |
75
|
|
|
{ |
76
|
|
|
if ($this->maxLength) { |
77
|
|
|
return $this->maxLength; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->getModelFieldLength(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setMaxLength($value) |
84
|
|
|
{ |
85
|
|
|
$value = intval($value); |
86
|
|
|
$this->maxLength = $value; |
87
|
|
|
$this->addValidationRule('max:' . $value); |
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getMinLength() |
92
|
|
|
{ |
93
|
|
|
return $this->minLength; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setMinLength($value) |
97
|
|
|
{ |
98
|
|
|
$value = intval($value); |
99
|
|
|
$this->minLength = $value; |
100
|
|
|
|
101
|
|
|
$this->addValidationRule('min:' . $value); |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function isReadonly() |
107
|
|
|
{ |
108
|
|
|
return $this->readonly; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function readonly() |
112
|
|
|
{ |
113
|
|
|
$this->readonly = true; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function toArray() |
119
|
|
|
{ |
120
|
|
|
return parent::toArray() + [ |
121
|
|
|
'minLength' => $this->getMinLength(), |
122
|
|
|
'maxLength' => $this->getMaxLength(), |
123
|
|
|
'size' => $this->getSize(), |
124
|
|
|
'readonly' => $this->isReadonly(), |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.