Skip to content

Commit 0dc31e7

Browse files
committed
IControl::setValue() β‡’ setCurrentValues() and Container::setValues() β‡’ setCurrentValues() [Closes #114]
1 parent 2277bf2 commit 0dc31e7

40 files changed

+147
-129
lines changed

β€Žexamples/custom-control.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct($label = NULL)
3131
}
3232

3333

34-
public function setValue($value)
34+
public function setCurrentValue($value)
3535
{
3636
if ($value === NULL) {
3737
$this->day = $this->month = $this->year = '';

β€Žsrc/Forms/Container.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function setDefaults($values, $erase = FALSE)
4242
{
4343
$form = $this->getForm(FALSE);
4444
if (!$form || !$form->isAnchored() || !$form->isSubmitted()) {
45-
$this->setValues($values, $erase);
45+
$this->setCurrentValues($values, $erase);
4646
}
4747
return $this;
4848
}
@@ -55,7 +55,7 @@ public function setDefaults($values, $erase = FALSE)
5555
* @return self
5656
* @internal
5757
*/
58-
public function setValues($values, $erase = FALSE)
58+
public function setCurrentValues($values, $erase = FALSE)
5959
{
6060
if ($values instanceof \Traversable) {
6161
$values = iterator_to_array($values);
@@ -67,25 +67,35 @@ public function setValues($values, $erase = FALSE)
6767
foreach ($this->getComponents() as $name => $control) {
6868
if ($control instanceof IControl) {
6969
if (array_key_exists($name, $values)) {
70-
$control->setValue($values[$name]);
70+
$control->setCurrentValue($values[$name]);
7171

7272
} elseif ($erase) {
73-
$control->setValue(NULL);
73+
$control->setCurrentValue(NULL);
7474
}
7575

7676
} elseif ($control instanceof self) {
7777
if (array_key_exists($name, $values)) {
78-
$control->setValues($values[$name], $erase);
78+
$control->setCurrentValues($values[$name], $erase);
7979

8080
} elseif ($erase) {
81-
$control->setValues([], $erase);
81+
$control->setCurrentValues([], $erase);
8282
}
8383
}
8484
}
8585
return $this;
8686
}
8787

8888

89+
/**
90+
* @deprecated
91+
*/
92+
public function setValues($values, $erase = FALSE)
93+
{
94+
trigger_error(__METHOD__ . '() is deprecated; use setCurrentValues() instead.', E_USER_DEPRECATED);
95+
return $this->setCurrentValues($values, $erase);
96+
}
97+
98+
8999
/**
90100
* Returns the values submitted by the form.
91101
* @param bool return values as an array?

β€Žsrc/Forms/Controls/BaseControl.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct($caption = NULL)
8686
if (self::$autoOptional) {
8787
$this->setRequired(FALSE);
8888
}
89-
$this->setValue(NULL);
89+
$this->setCurrentValue(NULL);
9090
}
9191

9292

@@ -120,7 +120,7 @@ public function getForm($need = TRUE)
120120
*/
121121
public function loadHttpData()
122122
{
123-
$this->setValue($this->getHttpData(Form::DATA_TEXT));
123+
$this->setCurrentValue($this->getHttpData(Form::DATA_TEXT));
124124
}
125125

126126

@@ -152,10 +152,18 @@ public function getHtmlName()
152152
* @return self
153153
* @internal
154154
*/
155+
public function setCurrentValue($value)
156+
{
157+
return $this->setValue($value);
158+
}
159+
160+
161+
/**
162+
* @deprecated
163+
*/
155164
public function setValue($value)
156165
{
157166
$this->value = $value;
158-
return $this;
159167
}
160168

161169

@@ -188,7 +196,7 @@ public function setDefaultValue($value)
188196
{
189197
$form = $this->getForm(FALSE);
190198
if ($this->isDisabled() || !$form || !$form->isAnchored() || !$form->isSubmitted()) {
191-
$this->setValue($value);
199+
$this->setCurrentValue($value);
192200
}
193201
return $this;
194202
}
@@ -202,7 +210,7 @@ public function setDefaultValue($value)
202210
public function setDisabled($value = TRUE)
203211
{
204212
if ($this->disabled = (bool) $value) {
205-
$this->setValue(NULL);
213+
$this->setCurrentValue(NULL);
206214
}
207215
return $this;
208216
}

β€Žsrc/Forms/Controls/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($label = NULL)
3737
* @return self
3838
* @internal
3939
*/
40-
public function setValue($value)
40+
public function setCurrentValue($value)
4141
{
4242
if (!is_scalar($value) && $value !== NULL) {
4343
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));

β€Žsrc/Forms/Controls/ChoiceControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function loadHttpData()
5757
* @return self
5858
* @internal
5959
*/
60-
public function setValue($value)
60+
public function setCurrentValue($value)
6161
{
6262
if ($this->checkAllowedValues && $value !== NULL && !array_key_exists((string) $value, $this->items)) {
6363
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, TRUE); }, array_keys($this->items))), 70, '...');

β€Žsrc/Forms/Controls/CsrfProtection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function attached($parent)
4848
* @return self
4949
* @internal
5050
*/
51-
public function setValue($value)
51+
public function setCurrentValue($value)
5252
{
5353
return $this;
5454
}

β€Žsrc/Forms/Controls/HiddenField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct($persistentValue = NULL)
3838
* @return self
3939
* @internal
4040
*/
41-
public function setValue($value)
41+
public function setCurrentValue($value)
4242
{
4343
if (!is_scalar($value) && $value !== NULL && !method_exists($value, '__toString')) {
4444
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));

β€Žsrc/Forms/Controls/MultiChoiceControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function loadHttpData()
5353
* @return self
5454
* @internal
5555
*/
56-
public function setValue($values)
56+
public function setCurrentValue($values)
5757
{
5858
if (is_scalar($values) || $values === NULL) {
5959
$values = (array) $values;

β€Žsrc/Forms/Controls/TextBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class TextBase extends BaseControl
3030
* @return self
3131
* @internal
3232
*/
33-
public function setValue($value)
33+
public function setCurrentValue($value)
3434
{
3535
if ($value === NULL) {
3636
$value = '';

β€Žsrc/Forms/Controls/TextInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($label = NULL, $maxLength = NULL)
3535
*/
3636
public function loadHttpData()
3737
{
38-
$this->setValue($this->getHttpData(Form::DATA_LINE));
38+
$this->setCurrentValue($this->getHttpData(Form::DATA_LINE));
3939
}
4040

4141

0 commit comments

Comments
Β (0)