urn:schemas-upnp-org:service:Layer3Forwarding:1 urn:upnp-org:serviceId:L3Forwarding1 /L3F.xml /ctl/L3F /evt/L3F */ use JsonSerializable; use SimpleXMLElement; class Service implements JsonSerializable { protected $device; protected $serviceType; protected $serviceId; protected $scpdUrl; protected $controlUrl; protected $eventSubUrl; 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; $this->controlUrl = (string)$spec->controlURL; $this->eventSubUrl = (string)$spec->eventSubURL; } public function getServiceType() { return $this->serviceType; } public function getServiceId() { return $this->serviceId; } public function getScpdUrl() { 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; } public function getEventSubUrl() { return $this->eventSubUrl; } public function __toString() { return sprintf("Service: %s [%s]\nControl URL: %s\nEventSub URL: %s\nSCPD URL: %s\n", $this->serviceId, $this->serviceType, $this->controlUrl, $this->eventSubUrl, $this->scpdUrl ); } public function jsonSerialize() { return get_object_vars($this); } }