-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCupsIppHttpClient.php
More file actions
58 lines (52 loc) · 1.78 KB
/
CupsIppHttpClient.php
File metadata and controls
58 lines (52 loc) · 1.78 KB
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
<?php
declare(strict_types=1);
namespace DR\Ipp\Client;
use DR\Ipp\Entity\IppServer;
use DR\Ipp\Entity\Response\IppResponseInterface;
use DR\Ipp\Enum\IppOperationEnum;
use DR\Ipp\Protocol\IppOperation;
use DR\Ipp\Protocol\IppResponseParserInterface;
use Nyholm\Psr7\Request;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
class CupsIppHttpClient implements IppHttpClientInterface
{
public function __construct(
private readonly IppServer $server,
private readonly ClientInterface $client,
private readonly IppResponseParserInterface $parser
) {
}
/**
* @param IppOperation $operation
*
* @return IppResponseInterface
* @throws ClientExceptionInterface
*/
public function sendRequest(IppOperation $operation): IppResponseInterface
{
if ($operation->getOperation()->value >= IppOperationEnum::CupsGetDefault->value) {
$response = $this->client->sendRequest(
new Request(
'POST',
$this->server->getUri() . '/admin',
[
'Content-Type' => 'application/ipp',
'Authorization' => 'Basic ' . base64_encode($this->server->getUsername() . ":" . $this->server->getPassword())
],
(string)$operation
)
);
} else {
$response = $this->client->sendRequest(
new Request(
'POST',
$this->server->getUri(),
['Content-Type' => 'application/ipp'],
(string)$operation
)
);
}
return $this->parser->getResponse($response->getBody()->getContents());
}
}