Path: blob/master/src/applications/auth/storage/PhabricatorAuthMessage.php
12256 views
<?php12final class PhabricatorAuthMessage3extends PhabricatorAuthDAO4implements5PhabricatorApplicationTransactionInterface,6PhabricatorPolicyInterface,7PhabricatorDestructibleInterface {89protected $messageKey;10protected $messageText;1112private $messageType = self::ATTACHABLE;1314public static function initializeNewMessage(15PhabricatorAuthMessageType $type) {1617return id(new self())18->setMessageKey($type->getMessageTypeKey())19->attachMessageType($type);20}2122protected function getConfiguration() {23return array(24self::CONFIG_AUX_PHID => true,25self::CONFIG_COLUMN_SCHEMA => array(26'messageKey' => 'text64',27'messageText' => 'text',28),29self::CONFIG_KEY_SCHEMA => array(30'key_type' => array(31'columns' => array('messageKey'),32'unique' => true,33),34),35) + parent::getConfiguration();36}3738public function getPHIDType() {39return PhabricatorAuthMessagePHIDType::TYPECONST;40}4142public function getObjectName() {43return pht('Auth Message %d', $this->getID());44}4546public function getURI() {47return urisprintf('/auth/message/%s/', $this->getID());48}4950public function attachMessageType(PhabricatorAuthMessageType $type) {51$this->messageType = $type;52return $this;53}5455public function getMessageType() {56return $this->assertAttached($this->messageType);57}5859public function getMessageTypeDisplayName() {60return $this->getMessageType()->getDisplayName();61}6263public static function loadMessage(64PhabricatorUser $viewer,65$message_key) {66return id(new PhabricatorAuthMessageQuery())67->setViewer($viewer)68->withMessageKeys(array($message_key))69->executeOne();70}7172public static function loadMessageText(73PhabricatorUser $viewer,74$message_key) {7576$message = self::loadMessage($viewer, $message_key);77if ($message) {78$message_text = $message->getMessageText();79if (strlen($message_text)) {80return $message_text;81}82}8384$message_type = PhabricatorAuthMessageType::newFromKey($message_key);8586return $message_type->getDefaultMessageText();87}888990/* -( PhabricatorPolicyInterface )----------------------------------------- */919293public function getCapabilities() {94return array(95PhabricatorPolicyCapability::CAN_VIEW,96PhabricatorPolicyCapability::CAN_EDIT,97);98}99100public function getPolicy($capability) {101switch ($capability) {102case PhabricatorPolicyCapability::CAN_VIEW:103return PhabricatorPolicies::getMostOpenPolicy();104default:105return false;106}107}108109public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {110switch ($capability) {111case PhabricatorPolicyCapability::CAN_VIEW:112// Even if an install doesn't allow public users, you can still view113// auth messages: otherwise, we can't do things like show you114// guidance on the login screen.115return true;116default:117return false;118}119}120121/* -( PhabricatorApplicationTransactionInterface )------------------------- */122123124public function getApplicationTransactionEditor() {125return new PhabricatorAuthMessageEditor();126}127128public function getApplicationTransactionTemplate() {129return new PhabricatorAuthMessageTransaction();130}131132133/* -( PhabricatorDestructibleInterface )----------------------------------- */134135136public function destroyObjectPermanently(137PhabricatorDestructionEngine $engine) {138$this->delete();139}140141}142143144