Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/field/PhabricatorSearchIntField.php
<?php | <?php | ||||
final class PhabricatorSearchIntField | final class PhabricatorSearchIntField | ||||
extends PhabricatorSearchField { | extends PhabricatorSearchField { | ||||
protected function getDefaultValue() { | protected function getDefaultValue() { | ||||
return null; | return null; | ||||
} | } | ||||
protected function getValueFromRequest(AphrontRequest $request, $key) { | protected function getValueFromRequest(AphrontRequest $request, $key) { | ||||
return $request->getInt($key); | // Use getStr() to differentiate in validateControlValue() between 0 | ||||
// literally entered versus 0 returned by PHP casting a string to an int | |||||
return $request->getStr($key); | |||||
} | |||||
public function getValueForQuery($value) { | |||||
return $this->validateControlValue($value); | |||||
speck: None of the returns in validateControlValue return anything. | |||||
} | |||||
protected function validateControlValue($value) { | |||||
if ($value === null || $value === '') { | |||||
return; | |||||
} | |||||
// Handle negative number strings by stripping the minus | |||||
if (($value[0] === '-' || $value[0] === '\xe2\x88\x92')) { | |||||
$value = substr($value, 1); | |||||
} | |||||
if (ctype_digit((string)$value)) { | |||||
return; | |||||
} | |||||
aviveyUnsubmitted Not Done Inline ActionsCan't this just be is_numeric() ? avivey: Can't this just be `is_numeric()` ? | |||||
aklapperAuthorUnsubmitted Done Inline Actions@avivey: Makes a difference for float values: Question is how lenient we want to be? aklapper: @avivey: Makes a difference for float values:
`is_numeric((string)$value)` allows entering e.g. | |||||
$this->addError( | |||||
pht('Invalid'), | |||||
pht('Integer value for "%s" can not be parsed.', $this->getLabel())); | |||||
} | } | ||||
protected function newControl() { | protected function newControl() { | ||||
return new AphrontFormTextControl(); | return new AphrontFormTextControl(); | ||||
} | } | ||||
protected function newConduitParameterType() { | protected function newConduitParameterType() { | ||||
return new ConduitIntParameterType(); | return new ConduitIntParameterType(); | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
None of the returns in validateControlValue return anything.