-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueServiceClient.php
More file actions
71 lines (62 loc) · 2.84 KB
/
Copy pathQueueServiceClient.php
File metadata and controls
71 lines (62 loc) · 2.84 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
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace AzureOss\Storage\Queue;
use AzureOss\Identity\TokenCredential;
use AzureOss\Storage\Common\Auth\StorageSharedKeyCredential;
use AzureOss\Storage\Common\Helpers\ConnectionStringHelper;
use AzureOss\Storage\Queue\Exceptions\InvalidConnectionStringException;
use AzureOss\Storage\Queue\Models\QueueClientOptions;
use AzureOss\Storage\Queue\Models\QueueServiceClientOptions;
use Psr\Http\Message\UriInterface;
/**
* Provides service-level access to queues in an Azure Storage account.
*/
final class QueueServiceClient
{
/**
* @param UriInterface $uri Queue service endpoint, including any SAS query string.
* @param StorageSharedKeyCredential|TokenCredential|null $credential Credential used to authorize requests, or null for SAS access.
* @param QueueServiceClientOptions $options Client transport and service-version options.
*/
public function __construct(
public UriInterface $uri,
public readonly StorageSharedKeyCredential|TokenCredential|null $credential = null,
private readonly QueueServiceClientOptions $options = new QueueServiceClientOptions,
) {
// must always include the forward slash (/) to separate the host name from the path and query portions of the URI.
$this->uri = $uri->withPath(rtrim($uri->getPath(), '/').'/');
}
/**
* Creates a client from an Azure Storage connection string.
*
* @throws InvalidConnectionStringException When the connection string does not contain a usable Queue endpoint and credential.
*/
public static function fromConnectionString(string $connectionString, QueueServiceClientOptions $options = new QueueServiceClientOptions): self
{
$uri = ConnectionStringHelper::getQueueEndpoint($connectionString);
if ($uri === null) {
throw new InvalidConnectionStringException;
}
$sas = ConnectionStringHelper::getSas($connectionString);
if ($sas !== null) {
return new self($uri->withQuery($sas), options: $options);
}
$accountName = ConnectionStringHelper::getAccountName($connectionString);
$accountKey = ConnectionStringHelper::getAccountKey($connectionString);
if ($accountName !== null && $accountKey !== null) {
return new self($uri, new StorageSharedKeyCredential($accountName, $accountKey), $options);
}
throw new InvalidConnectionStringException;
}
/**
* Creates a client for the named queue without making a service request.
*/
public function getQueueClient(string $queueName): QueueClient
{
return new QueueClient(
$this->uri->withPath($this->uri->getPath().$queueName),
$this->credential,
new QueueClientOptions($this->options->httpClientOptions, $this->options->apiVersion),
);
}
}