Various improvements

This commit is contained in:
2017-02-18 13:12:36 +01:00
parent ccc70650f2
commit a9c1a3ccbe
7 changed files with 185 additions and 22 deletions

View File

@ -10,10 +10,13 @@ namespace NoccyLabs\UPnP\SSDP;
<eventSubURL>/evt/L3F</eventSubURL>
*/
use JsonSerializable;
use SimpleXMLElement;
class Service
class Service implements JsonSerializable
{
protected $device;
protected $serviceType;
protected $serviceId;
@ -24,9 +27,10 @@ class Service
protected $eventSubUrl;
public function __construct(SimpleXMLElement $spec)
public function __construct(Device $device, SimpleXMLElement $spec)
{
$this->device = $device;
$this->serviceType = (string)$spec->serviceType;
$this->serviceId = (string)$spec->serviceId;
$this->scpdUrl = (string)$spec->SCPDURL;
@ -50,6 +54,26 @@ class Service
return $this->scpdUrl;
}
public function getServiceUrl()
{
if (strpos($this->scpdUrl,"://")!==false) {
return $this->scpdUrl;
}
$dev = ['user'=>null, 'pass'=>null, 'port'=>80, 'path'=>null];
$dev = array_merge($dev, parse_url($this->device->getUrl()));
$url = $this->scpdUrl;
$auth = $dev['user']?($dev['user'].":".$dev['path']):"";
$base = $dev['scheme']."://".$dev['host'].":".($dev['port']?:80);
if ($url[0]=="/") {
return $base.$url;
} else {
return $base.rtrim($dev['path'],"/")."/".$url;
}
}
public function getControlUrl()
{
return $this->controlUrl;
@ -71,5 +95,10 @@ class Service
);
}
public function jsonSerialize()
{
return get_object_vars($this);
}
}