Path: blob/master/src/applications/passphrase/xaction/PassphraseCredentialUsernameTransaction.php
12256 views
<?php12final class PassphraseCredentialUsernameTransaction3extends PassphraseCredentialTransactionType {45const TRANSACTIONTYPE = 'passphrase:username';67public function generateOldValue($object) {8return $object->getUsername();9}1011public function applyInternalEffects($object, $value) {12$object->setUsername($value);13}1415public function getTitle() {16return pht(17'%s set the username for this credential to %s.',18$this->renderAuthor(),19$this->renderNewValue());20}2122public function getTitleForFeed() {23return pht(24'%s set the username for credential %s to %s.',25$this->renderAuthor(),26$this->renderObject(),27$this->renderNewValue());28}2930public function validateTransactions($object, array $xactions) {31$errors = array();3233$credential_type = $object->getImplementation();34if ($credential_type->shouldRequireUsername()) {35if ($this->isEmptyTextTransaction($object->getUsername(), $xactions)) {36$errors[] = $this->newRequiredError(37pht('This credential must have a username.'));38}39}4041$max_length = $object->getColumnMaximumByteLength('username');42foreach ($xactions as $xaction) {43$new_value = $xaction->getNewValue();44$new_length = strlen($new_value);45if ($new_length > $max_length) {46$errors[] = $this->newInvalidError(47pht('The username can be no longer than %s characters.',48new PhutilNumber($max_length)));49}50}5152return $errors;53}5455}565758