Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractAuth
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
7 / 7
7
100.00% covered (success)
100.00%
1 / 1
 setAccountName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAccountName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasAccountName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAccountKey
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAccountKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasAccountKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getBaseUri
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthorizationHeader
n/a
0 / 0
n/a
0 / 0
0
 signRequest
n/a
0 / 0
n/a
0 / 0
0
 generateSasToken
n/a
0 / 0
n/a
0 / 0
0
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Storage\Adapter\Azure;
16
17use Pop\Http\Client\Request;
18
19/**
20 * Azure storage abstract auth class
21 *
22 * @category   Pop
23 * @package    Pop\Storage
24 * @author     Nick Sagona, III <nick@popphp.org>
25 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
26 * @license    https://www.popphp.org/license     New BSD License
27 * @version    3.0.0
28 */
29abstract class AbstractAuth implements AuthInterface
30{
31
32    /**
33     * Account name
34     * @var ?string
35     */
36    protected ?string $accountName = null;
37
38    /**
39     * Account key
40     * @var ?string
41     */
42    protected ?string $accountKey = null;
43
44    /**
45     * Set account name
46     *
47     * @param  string $accountName
48     * @return AbstractAuth
49     */
50    public function setAccountName(string $accountName): AbstractAuth
51    {
52        $this->accountName = $accountName;
53        return $this;
54    }
55
56    /**
57     * Get account name
58     *
59     * @return ?string
60     */
61    public function getAccountName(): ?string
62    {
63        return $this->accountName;
64    }
65
66    /**
67     * Has account name
68     *
69     * @return bool
70     */
71    public function hasAccountName(): bool
72    {
73        return ($this->accountName !== null);
74    }
75
76    /**
77     * Set account key
78     *
79     * @param  string $accountKey
80     * @return AbstractAuth
81     */
82    public function setAccountKey(string $accountKey): AbstractAuth
83    {
84        $this->accountKey = $accountKey;
85        return $this;
86    }
87
88    /**
89     * Get account key
90     *
91     * @return ?string
92     */
93    public function getAccountKey(): ?string
94    {
95        return $this->accountKey;
96    }
97
98    /**
99     * Has account key
100     *
101     * @return bool
102     */
103    public function hasAccountKey(): bool
104    {
105        return ($this->accountKey !== null);
106    }
107
108    /**
109     * Get account key
110     *
111     * @return string
112     */
113    public function getBaseUri(): string
114    {
115        return 'https://' . $this->accountName . '.blob.core.windows.net';
116    }
117
118    /**
119     * Returns authorization header to be included in the request.
120     *
121     * @param  array  $headers
122     * @param  string $url
123     * @param  array  $queryParams
124     * @param  string $httpMethod
125     * @return string
126     */
127    abstract public function getAuthorizationHeader(array $headers, string $url, array $queryParams, string $httpMethod): string;
128
129    /**
130     * Adds authentication header to the request headers.
131     *
132     * @param  Request $request
133     * @return Request
134     */
135    abstract public function signRequest(Request $request): Request;
136
137    /**
138     * Generate a service SAS token for a blob
139     *
140     * @param  string     $resourcePath  e.g. '/container/blob.txt'
141     * @param  int        $expiresInSeconds
142     * @param  string     $permissions   e.g. 'r' for read-only
143     * @param  ?\DateTime $expiresAt     explicit expiry, overriding $expiresInSeconds (mainly for tests)
144     * @return string
145     */
146    abstract public function generateSasToken(
147        string $resourcePath, int $expiresInSeconds, string $permissions = 'r', ?\DateTime $expiresAt = null
148    ): string;
149
150}