-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathText.php
More file actions
56 lines (46 loc) · 1.07 KB
/
Text.php
File metadata and controls
56 lines (46 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php declare( strict_types = 1 );
namespace lloc\Msls\Component\Input;
use lloc\Msls\Component\Component;
final class Text extends Component {
const DEFAULT_SIZE = 30;
/**
* @var string
*/
protected $key;
/**
* @var ?string
*/
protected $value;
/**
* @var int
*/
protected $size;
/**
* @var string
*/
protected $readonly;
/**
* @param string $key
* @param string|null $value
* @param int $size
* @param bool $read_only
*/
public function __construct( string $key, ?string $value, int $size = self::DEFAULT_SIZE, bool $read_only = false ) {
$this->key = $key;
$this->value = $value;
$this->size = $size;
$this->readonly = $read_only ? ' readonly="readonly"' : '';
}
/**
* @return string
*/
public function render(): string {
return sprintf(
'<input type="text" class="regular-text" id="%1$s" name="msls[%1$s]" value="%2$s" size="%3$d"%4$s/>',
esc_attr( $this->key ),
esc_attr( (string) $this->value ),
$this->size,
$this->readonly // phpcs:ignore WordPress.Security.EscapeOutput
);
}
}