1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Christoph Wurst <[email protected]> |
7
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace OCA\TwoFactorGateway\Provider\Channel\SMS\Provider; |
11
|
|
|
|
12
|
|
|
use OCA\TwoFactorGateway\Exception\MessageTransmissionException; |
13
|
|
|
use OCA\TwoFactorGateway\Provider\Gateway\TConfigurable; |
14
|
|
|
use OCA\TwoFactorGateway\Provider\Settings; |
15
|
|
|
use OCP\IAppConfig; |
16
|
|
|
|
17
|
|
|
abstract class AProvider implements IProvider { |
18
|
|
|
use TConfigurable; |
|
|
|
|
19
|
|
|
public IAppConfig $appConfig; |
20
|
|
|
protected ?Settings $settings = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @throws MessageTransmissionException |
24
|
|
|
*/ |
25
|
|
|
#[\Override] |
26
|
|
|
abstract public function send(string $identifier, string $message); |
27
|
|
|
|
28
|
8 |
|
#[\Override] |
29
|
|
|
public function setAppConfig(IAppConfig $appConfig): void { |
30
|
8 |
|
$this->appConfig = $appConfig; |
31
|
|
|
} |
32
|
|
|
|
33
|
7 |
|
#[\Override] |
34
|
|
|
public function getSettings(): Settings { |
35
|
7 |
|
if ($this->settings !== null) { |
36
|
5 |
|
return $this->settings; |
37
|
|
|
} |
38
|
6 |
|
return $this->settings = $this->createSettings(); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
#[\Override] |
42
|
|
|
public static function idOverride(): ?string { |
43
|
|
|
return null; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
#[\Override] |
47
|
|
|
public function getProviderId(): string { |
48
|
|
|
$settings = $this->getSettings(); |
49
|
|
|
if (!empty($settings->id)) { |
50
|
|
|
return $settings->id; |
51
|
|
|
} |
52
|
|
|
$id = self::getIdFromProviderFqcn(static::class); |
53
|
|
|
if ($id === null) { |
54
|
|
|
throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
55
|
|
|
} |
56
|
|
|
return $id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private static function getIdFromProviderFqcn(string $fqcn): ?string { |
60
|
|
|
$prefix = 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\'; |
61
|
|
|
if (strncmp($fqcn, $prefix, strlen($prefix)) !== 0) { |
62
|
|
|
return null; |
63
|
|
|
} |
64
|
|
|
$type = substr($fqcn, strlen($prefix)); |
65
|
|
|
if (strpos($type, '\\') !== false) { |
66
|
|
|
return null; |
67
|
|
|
} |
68
|
|
|
return $type !== '' ? strtolower($type) : null; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|