duncan3dc\Sonos\Device::soap PHP Method

soap() public method

Send a soap request to the device.
public soap ( string $service, string $action, array $params = [] ) : mixed
$service string The service to send the request to
$action string The action to call
$params array The parameters to pass
return mixed
    public function soap($service, $action, array $params = [])
    {
        switch ($service) {
            case "AVTransport":
            case "RenderingControl":
                $path = "MediaRenderer";
                break;
            case "ContentDirectory":
                $path = "MediaServer";
                break;
            case "AlarmClock":
            case "DeviceProperties":
                $path = null;
                break;
            default:
                throw new \InvalidArgumentException("Unknown service: {$service}");
        }
        $location = "http://{$this->ip}:1400/";
        if (is_string($path)) {
            $location .= "{$path}/";
        }
        $location .= "{$service}/Control";
        $this->logger->info("sending soap request to: {$location}", $params);
        $soap = new \SoapClient(null, ["location" => $location, "uri" => "urn:schemas-upnp-org:service:{$service}:1", "trace" => true]);
        $soapParams = [];
        $params["InstanceID"] = 0;
        foreach ($params as $key => $val) {
            $soapParams[] = new \SoapParam(new \SoapVar($val, \XSD_STRING), $key);
        }
        try {
            return $soap->__soapCall($action, $soapParams);
        } catch (\SoapFault $e) {
            throw new Exceptions\SoapException($e, $soap);
        }
    }