1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?php
/**
* @type SIP
*
* form a SIP uri. Additionally
* prepend protocol if needed
* as Catapult takes:
*
* sip:someuser@somedomain.com
*/
namespace Catapult;
final class SIP extends Types {
/* Construct
* a SIP object
* takes a string as
* input HAS to be
* valid sip
* see: https://www.ietf.org/rfc/rfc3261.txt
*/
public function __construct($sipurl)
{
$this->sip = $sipurl;
}
/**
* checks if the SIP
* URI is valid according
* to rfc3261
*
* where input should follow
* sip:user@domain.com
*
*/
public function isValid()
{
if (preg_match("/(sip:)?(.*)\@(.*)\.(.*)/", $this->sip)) {
return true;
}
return false;
}
/* do we already
* have sip in the
* address?
*/
public function __toString()
{
$m = array();
preg_match("/^sip:/", $this->sip, $m);
if (sizeof($m) > 0) {
return $this->sip;
}
return "sip:" . $this->sip;
}
}