View.php
1.45 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace ACP\Editing;
use InvalidArgumentException;
class View {
/**
* @var array
*/
protected $args;
public function __construct( $type ) {
$this->set( 'type', (string) $type );
}
protected function set( $key, $value ) {
if ( ! $this->validate( $value ) ) {
throw new InvalidArgumentException( 'Invalid value.' );
}
if ( is_array( $value ) ) {
$value = array_replace( (array) $this->get_arg( $key ), $value );
}
$this->args[ $key ] = $value;
return $this;
}
public function get_arg( $key ) {
return isset( $this->args[ $key ] )
? $this->args[ $key ]
: null;
}
private function validate( $value ) {
return is_array( $value ) || is_scalar( $value );
}
/**
* @param bool $enable
*/
public function set_clear_button( $enable ) {
$this->set( 'clear_button', (bool) $enable );
return $this;
}
/**
* @param bool $required
*
* @return $this
*/
public function set_required( $required ) {
$this->set( 'required', (bool) $required );
return $this;
}
/**
* @param bool $enable
*
* @return $this
*/
public function set_revisioning( $enable ) {
$this->set( 'disable_revisioning', ! $enable );
return $this;
}
/**
* @param string $selector
*
* @return $this
*/
public function set_js_selector( $selector ) {
$this->set( 'js', [
'selector' => (string) $selector,
] );
return $this;
}
/**
* @return array
*/
public function get_args() {
return $this->args;
}
}