PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8
GiveWP – Donation Plugin and Fundraising Platform v4.16.8
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / vendor / vendor-prefixed / stellarwp / licensing-api-client / src / Http / AuthContext.php
AuthContext.php
56 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace Give\Vendors\LiquidWeb\LicensingApiClient\Http;
4
5 use InvalidArgumentException;
6
7 /**
8 * Represents the authentication mode the API client should use for a request.
9 */
10 final class AuthContext
11 {
12 public const MODE_AUTO = 'auto';
13 public const MODE_NONE = 'none';
14 public const MODE_CONFIGURED = 'configured';
15 public const MODE_EXPLICIT = 'explicit';
16
17 private string $mode;
18
19 /**
20 * @throws InvalidArgumentException
21 */
22 public function __construct(string $mode = self::MODE_AUTO) {
23 $this->assertValidMode($mode);
24
25 $this->mode = $mode;
26 }
27
28 /**
29 * @throws InvalidArgumentException
30 */
31 private function assertValidMode(string $mode): void {
32 $validModes = [
33 self::MODE_AUTO,
34 self::MODE_NONE,
35 self::MODE_CONFIGURED,
36 self::MODE_EXPLICIT,
37 ];
38
39 if ( ! in_array($mode, $validModes, true)) {
40 throw new InvalidArgumentException('Unsupported auth mode [' . $mode . '].');
41 }
42 }
43
44 public function requiresToken(): bool {
45 return $this->mode === self::MODE_CONFIGURED || $this->mode === self::MODE_EXPLICIT;
46 }
47
48 public function equals(self $authContext): bool {
49 return $this->mode === $authContext->mode();
50 }
51
52 public function mode(): string {
53 return $this->mode;
54 }
55 }
56