Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/xaction/AlmanacInterfacePortTransaction.php
12256 views
1
<?php
2
3
final class AlmanacInterfacePortTransaction
4
extends AlmanacInterfaceTransactionType {
5
6
const TRANSACTIONTYPE = 'almanac:interface:port';
7
8
public function generateOldValue($object) {
9
$port = $object->getPort();
10
11
if ($port !== null) {
12
$port = (int)$port;
13
}
14
15
return $port;
16
}
17
18
public function applyInternalEffects($object, $value) {
19
$object->setPort((int)$value);
20
}
21
22
public function getTitle() {
23
return pht(
24
'%s changed the port for this interface from %s to %s.',
25
$this->renderAuthor(),
26
$this->renderOldValue(),
27
$this->renderNewValue());
28
}
29
30
public function validateTransactions($object, array $xactions) {
31
$errors = array();
32
33
if ($this->isEmptyTextTransaction($object->getPort(), $xactions)) {
34
$errors[] = $this->newRequiredError(
35
pht('Interfaces must have a port number.'));
36
}
37
38
foreach ($xactions as $xaction) {
39
$port = $xaction->getNewValue();
40
41
$port = (int)$port;
42
if ($port < 1 || $port > 65535) {
43
$errors[] = $this->newInvalidError(
44
pht('Port numbers must be between 1 and 65535, inclusive.'),
45
$xaction);
46
continue;
47
}
48
}
49
50
return $errors;
51
}
52
53
}
54
55