Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / xaction / PhabricatorRepositoryEncodingTransaction.php
blobef129da83208040c9a8b078ab9fa83674409859e
1 <?php
3 final class PhabricatorRepositoryEncodingTransaction
4 extends PhabricatorRepositoryTransactionType {
6 const TRANSACTIONTYPE = 'repo:encoding';
8 public function generateOldValue($object) {
9 return $object->getDetail('encoding');
12 public function applyInternalEffects($object, $value) {
13 $object->setDetail('encoding', $value);
16 public function getTitle() {
17 $old = $this->getOldValue();
18 $new = $this->getNewValue();
20 if (strlen($old) && !strlen($new)) {
21 return pht(
22 '%s removed the %s encoding configured for this repository.',
23 $this->renderAuthor(),
24 $this->renderOldValue());
25 } else if (strlen($new) && !strlen($old)) {
26 return pht(
27 '%s set the encoding for this repository to %s.',
28 $this->renderAuthor(),
29 $this->renderNewValue());
30 } else {
31 return pht(
32 '%s changed the repository encoding from %s to %s.',
33 $this->renderAuthor(),
34 $this->renderOldValue(),
35 $this->renderNewValue());
39 public function validateTransactions($object, array $xactions) {
40 $errors = array();
42 foreach ($xactions as $xaction) {
43 // Make sure the encoding is valid by converting to UTF-8. This tests
44 // that the user has mbstring installed, and also that they didn't
45 // type a garbage encoding name. Note that we're converting from
46 // UTF-8 to the target encoding, because mbstring is fine with
47 // converting from a nonsense encoding.
48 $encoding = $xaction->getNewValue();
49 if (!strlen($encoding)) {
50 continue;
53 try {
54 phutil_utf8_convert('.', $encoding, 'UTF-8');
55 } catch (Exception $ex) {
56 $errors[] = $this->newInvalidError(
57 pht(
58 'Repository encoding "%s" is not valid: %s',
59 $encoding,
60 $ex->getMessage()),
61 $xaction);
65 return $errors;