Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/httpparametertype/AphrontBoolHTTPParameterType.php
<?php | <?php | ||||
final class AphrontBoolHTTPParameterType | final class AphrontBoolHTTPParameterType | ||||
extends AphrontHTTPParameterType { | extends AphrontHTTPParameterType { | ||||
protected function getParameterExists(AphrontRequest $request, $key) { | |||||
if ($request->getExists($key)) { | |||||
return true; | |||||
} | |||||
$checkbox_key = $this->getCheckboxKey($key); | |||||
if ($request->getExists($checkbox_key)) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
protected function getParameterValue(AphrontRequest $request, $key) { | protected function getParameterValue(AphrontRequest $request, $key) { | ||||
return $request->getBool($key); | return (bool)$request->getBool($key); | ||||
} | } | ||||
protected function getParameterTypeName() { | protected function getParameterTypeName() { | ||||
return 'bool'; | return 'bool'; | ||||
} | } | ||||
protected function getParameterFormatDescriptions() { | protected function getParameterFormatDescriptions() { | ||||
return array( | return array( | ||||
pht('A boolean value (true or false).'), | pht('A boolean value (true or false).'), | ||||
); | ); | ||||
} | } | ||||
protected function getParameterExamples() { | protected function getParameterExamples() { | ||||
return array( | return array( | ||||
'v=true', | 'v=true', | ||||
'v=false', | 'v=false', | ||||
'v=1', | 'v=1', | ||||
'v=0', | 'v=0', | ||||
); | ); | ||||
} | } | ||||
public function getCheckboxKey($key) { | |||||
return "{$key}.exists"; | |||||
} | |||||
} | } |