* @copyright 2014 Fabian Grutschus. All rights reserved. * @license BSD * @link http://github.com/fabiang/xmpp */ namespace Fabiang\Xmpp\Protocol; use Fabiang\Xmpp\Util\XML; /** * Protocol setting for Xmpp. * * @package Xmpp\Protocol */ class Presence implements ProtocolImplementationInterface { /** * Signals that the entity is available for communication. */ const TYPE_AVAILABLE = 'available'; /** * Signals that the entity is no longer available for communication. */ const TYPE_UNAVAILABLE = 'unavailable'; /** * The sender wishes to subscribe to the recipient's presence. */ const TYPE_SUBSCRIBE = 'subscribe'; /** * The sender has allowed the recipient to receive their presence. */ const TYPE_SUBSCRIBED = 'subscribed'; /** * The sender is unsubscribing from another entity's presence. */ const TYPE_UNSUBSCRIBE = 'unsubscribe'; /** * The subscription request has been denied or a previously-granted subscription has been cancelled. */ const TYPE_UNSUBSCRIBED = 'unsubscribed'; /** * A request for an entity's current presence; SHOULD be generated only by a server on behalf of a user. */ const TYPE_PROBE = 'probe'; /** * An error has occurred regarding processing or delivery of a previously-sent presence stanza. */ const TYPE_ERROR = 'error'; /** * The entity or resource is available. */ const SHOW_AVAILABLE = 'available'; /** * The entity or resource is temporarily away. */ const SHOW_AWAY = 'away'; /** * The entity or resource is actively interested in chatting. */ const SHOW_CHAT = 'chat'; /** * The entity or resource is busy (dnd = "Do Not Disturb"). */ const SHOW_DND = 'dnd'; /** * The entity or resource is away for an extended period (xa = "eXtended Away"). */ const SHOW_XA = 'xa'; /** * Presence to. * * @var string|null */ protected $to; /** * Priority. * * @var integer */ protected $priority = 1; /** * Nickname for presence. * * @var string */ protected $nickname; /** * Channel password. * * @var string */ protected $password; /** * Constructor. * * @param integer $priority * @param string $to * @param string $nickname */ public function __construct($priority = 1, $to = null, $nickname = null) { $this->setPriority($priority)->setTo($to)->setNickname($nickname); } /** * {@inheritDoc} */ public function toString() { $presence = 'getTo()) { $presence .= ' to="' . XML::quote($this->getTo()) . '/' . XML::quote($this->getNickname()) . '"'; } $presence .= '>' . $this->getPriority() . ''; if (null !== $this->getPassword()) { $presence .= "" . $this->getPassword() . ""; } $presence .= ''; return $presence; } /** * Get nickname. * * @return string */ public function getNickname() { return $this->nickname; } /** * Set nickname. * * @param string $nickname * @return $this */ public function setNickname($nickname) { $this->nickname = (string) $nickname; return $this; } /** * Get to. * * @return string¦null */ public function getTo() { return $this->to; } /** * Set to. * * @param string|null $to * @return $this */ public function setTo($to = null) { $this->to = $to; return $this; } /** * Get priority. * * @return integer */ public function getPriority() { return $this->priority; } /** * Set priority. * * @param integer $priority * @return $this */ public function setPriority($priority) { $this->priority = (int) $priority; return $this; } /** * Get channel password. * * @return string¦null */ public function getPassword() { return $this->password; } /** * Set channel password. * * @param string|null $to * @return $this */ public function setPassword($password = null) { $this->password = $password; return $this; } }