Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / standard / PhabricatorStandardCustomFieldInt.php
blobc485ace1622bf69293a64da88ed070cd03aa1e75
1 <?php
3 final class PhabricatorStandardCustomFieldInt
4 extends PhabricatorStandardCustomField {
6 public function getFieldType() {
7 return 'int';
10 public function buildFieldIndexes() {
11 $indexes = array();
13 $value = $this->getFieldValue();
14 if (strlen($value)) {
15 $indexes[] = $this->newNumericIndex((int)$value);
18 return $indexes;
21 public function buildOrderIndex() {
22 return $this->newNumericIndex(0);
25 public function getValueForStorage() {
26 $value = $this->getFieldValue();
27 if ($value !== null && strlen($value)) {
28 return $value;
29 } else {
30 return null;
34 public function setValueFromStorage($value) {
35 if (strlen($value)) {
36 $value = (int)$value;
37 } else {
38 $value = null;
40 return $this->setFieldValue($value);
43 public function readApplicationSearchValueFromRequest(
44 PhabricatorApplicationSearchEngine $engine,
45 AphrontRequest $request) {
47 return $request->getStr($this->getFieldKey());
50 public function applyApplicationSearchConstraintToQuery(
51 PhabricatorApplicationSearchEngine $engine,
52 PhabricatorCursorPagedPolicyAwareQuery $query,
53 $value) {
55 if (strlen($value)) {
56 $query->withApplicationSearchContainsConstraint(
57 $this->newNumericIndex(null),
58 $value);
62 public function appendToApplicationSearchForm(
63 PhabricatorApplicationSearchEngine $engine,
64 AphrontFormView $form,
65 $value) {
67 $form->appendChild(
68 id(new AphrontFormTextControl())
69 ->setLabel($this->getFieldName())
70 ->setName($this->getFieldKey())
71 ->setValue($value));
74 public function validateApplicationTransactions(
75 PhabricatorApplicationTransactionEditor $editor,
76 $type,
77 array $xactions) {
79 $errors = parent::validateApplicationTransactions(
80 $editor,
81 $type,
82 $xactions);
84 foreach ($xactions as $xaction) {
85 $value = $xaction->getNewValue();
86 if (strlen($value)) {
87 if (!preg_match('/^-?\d+/', $value)) {
88 $errors[] = new PhabricatorApplicationTransactionValidationError(
89 $type,
90 pht('Invalid'),
91 pht('%s must be an integer.', $this->getFieldName()),
92 $xaction);
93 $this->setFieldError(pht('Invalid'));
98 return $errors;
101 public function getApplicationTransactionHasEffect(
102 PhabricatorApplicationTransaction $xaction) {
104 $old = $xaction->getOldValue();
105 $new = $xaction->getNewValue();
106 if (!strlen($old) && strlen($new)) {
107 return true;
108 } else if (strlen($old) && !strlen($new)) {
109 return true;
110 } else {
111 return ((int)$old !== (int)$new);
115 protected function getHTTPParameterType() {
116 return new AphrontIntHTTPParameterType();
119 protected function newConduitSearchParameterType() {
120 return new ConduitIntParameterType();
123 protected function newConduitEditParameterType() {
124 return new ConduitIntParameterType();
127 protected function newExportFieldType() {
128 return new PhabricatorIntExportField();