1 | <?php |
||
14 | class InputElement extends Element |
||
15 | { |
||
16 | /** |
||
17 | * @var LabelElement |
||
18 | */ |
||
19 | protected $label = null; |
||
20 | |||
21 | /** |
||
22 | * @var bool if the element should reflect posted values |
||
23 | */ |
||
24 | protected $useInput = true; |
||
25 | |||
26 | /** |
||
27 | * @param string $type The type of this element |
||
28 | * @param string $name The name of this form element |
||
29 | * @param string $label The label text for this element (will be autoescaped) |
||
30 | */ |
||
31 | public function __construct($type, $name, $label = '') |
||
38 | |||
39 | /** |
||
40 | * Returns the label element if there's one set |
||
41 | * |
||
42 | * @return LabelElement|null |
||
43 | */ |
||
44 | public function getLabel() |
||
48 | |||
49 | /** |
||
50 | * Should the user sent input be used to initialize the input field |
||
51 | * |
||
52 | * The default is true. Any set values will be overwritten by the INPUT |
||
53 | * provided values. |
||
54 | * |
||
55 | * @param bool $useinput |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function useInput($useinput) |
||
63 | |||
64 | /** |
||
65 | * Get or set the element's ID |
||
66 | * |
||
67 | * @param null|string $id |
||
68 | * @return string|$this |
||
69 | */ |
||
70 | public function id($id = null) |
||
75 | |||
76 | /** |
||
77 | * Adds a class to the class attribute |
||
78 | * |
||
79 | * This is the preferred method of setting the element's class |
||
80 | * |
||
81 | * @param string $class the new class to add |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function addClass($class) |
||
89 | |||
90 | /** |
||
91 | * Figures out how to access the value for this field from INPUT data |
||
92 | * |
||
93 | * The element's name could have been given as a simple string ('foo') |
||
94 | * or in array notation ('foo[bar]'). |
||
95 | * |
||
96 | * Note: this function only handles one level of arrays. If your data |
||
97 | * is nested deeper, you should call useInput(false) and set the |
||
98 | * correct value yourself |
||
99 | * |
||
100 | * @return array name and array key (null if not an array) |
||
101 | */ |
||
102 | protected function getInputName() |
||
103 | { |
||
104 | $name = $this->attr('name'); |
||
105 | parse_str("$name=1", $parsed); |
||
106 | |||
107 | $name = array_keys($parsed); |
||
108 | $name = array_shift($name); |
||
109 | |||
110 | if (isset($parsed[$name]) && is_array($parsed[$name])) { |
||
111 | $key = array_keys($parsed[$name]); |
||
112 | $key = array_shift($key); |
||
113 | } else { |
||
114 | $key = null; |
||
115 | } |
||
116 | |||
117 | return array($name, $key); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Handles the useInput flag and set the value attribute accordingly |
||
122 | */ |
||
123 | protected function prefillInput() |
||
142 | |||
143 | /** |
||
144 | * The HTML representation of this element |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function mainElementHTML() |
||
153 | |||
154 | /** |
||
155 | * The HTML representation of this element wrapped in a label |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function toHTML() |
||
170 | } |
||
171 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.