@@ 19-49 (lines=31) @@ | ||
16 | * |
|
17 | * @package GravityMedia\Ssdp\Request\Factory |
|
18 | */ |
|
19 | class ByebyeFactory implements FactoryInterface |
|
20 | { |
|
21 | /** |
|
22 | * Create byebye request object |
|
23 | * |
|
24 | * @param ByebyeOptions $options |
|
25 | * |
|
26 | * @throws \RuntimeException |
|
27 | * |
|
28 | * @return RequestInterface |
|
29 | */ |
|
30 | public function createRequest($options) |
|
31 | { |
|
32 | if (!$options instanceof ByebyeOptions) { |
|
33 | throw new \RuntimeException('Options must be instance of ' . ByebyeOptions::class); |
|
34 | } |
|
35 | ||
36 | if (null === $options->getUniqueServiceName()) { |
|
37 | throw new \RuntimeException('Unique service name not specified.'); |
|
38 | } |
|
39 | ||
40 | $request = new NotifyRequest(); |
|
41 | return $request |
|
42 | ->withRequestTarget('*') |
|
43 | ->withProtocolVersion('1.1') |
|
44 | ->withHeader('HOST', (string)$request->getUri()) |
|
45 | ->withHeader('NT', (string)$options->getNotificationType()) |
|
46 | ->withHeader('NTS', '"ssdp:byebye"') |
|
47 | ->withHeader('USN', (string)$options->getUniqueServiceName()); |
|
48 | } |
|
49 | } |
|
50 |
@@ 19-50 (lines=32) @@ | ||
16 | * |
|
17 | * @package GravityMedia\Ssdp\Request\Factory |
|
18 | */ |
|
19 | class UpdateFactory implements FactoryInterface |
|
20 | { |
|
21 | /** |
|
22 | * Create update request object |
|
23 | * |
|
24 | * @param UpdateOptions $options |
|
25 | * |
|
26 | * @throws \RuntimeException |
|
27 | * |
|
28 | * @return RequestInterface |
|
29 | */ |
|
30 | public function createRequest($options) |
|
31 | { |
|
32 | if (!$options instanceof UpdateOptions) { |
|
33 | throw new \RuntimeException('Options must be instance of ' . UpdateOptions::class); |
|
34 | } |
|
35 | ||
36 | if (null === $options->getUniqueServiceName()) { |
|
37 | throw new \RuntimeException('Unique service name not specified.'); |
|
38 | } |
|
39 | ||
40 | $request = new NotifyRequest(); |
|
41 | return $request |
|
42 | ->withRequestTarget('*') |
|
43 | ->withProtocolVersion('1.1') |
|
44 | ->withHeader('HOST', (string)$request->getUri()) |
|
45 | ->withHeader('LOCATION', (string)$options->getDescriptionUrl()) |
|
46 | ->withHeader('NT', (string)$options->getNotificationType()) |
|
47 | ->withHeader('NTS', '"ssdp:update"') |
|
48 | ->withHeader('USN', (string)$options->getUniqueServiceName()); |
|
49 | } |
|
50 | } |
|
51 |