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\Telegram\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
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
abstract class AProvider implements IProvider { |
20
|
|
|
use TConfigurable; |
|
|
|
|
21
|
|
|
public IAppConfig $appConfig; |
22
|
|
|
protected ?Settings $settings = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @throws MessageTransmissionException |
26
|
|
|
*/ |
27
|
|
|
#[\Override] |
28
|
|
|
abstract public function send(string $identifier, string $message); |
29
|
|
|
|
30
|
1 |
|
#[\Override] |
31
|
|
|
public function setAppConfig(IAppConfig $appConfig): void { |
32
|
1 |
|
$this->appConfig = $appConfig; |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
#[\Override] |
36
|
|
|
public function getSettings(): Settings { |
37
|
1 |
|
if ($this->settings !== null) { |
38
|
1 |
|
return $this->settings; |
39
|
|
|
} |
40
|
1 |
|
return $this->settings = $this->createSettings(); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
#[\Override] |
44
|
|
|
public static function idOverride(): ?string { |
45
|
|
|
return null; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
#[\Override] |
49
|
|
|
public function getProviderId(): string { |
50
|
|
|
$settings = $this->getSettings(); |
51
|
|
|
if (!empty($settings->id)) { |
52
|
|
|
return $settings->id; |
53
|
|
|
} |
54
|
|
|
$id = self::getIdFromProviderFqcn(static::class); |
55
|
|
|
if ($id === null) { |
56
|
|
|
throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
57
|
|
|
} |
58
|
|
|
return $id; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
#[\Override] |
62
|
|
|
abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
63
|
|
|
|
64
|
|
|
private static function getIdFromProviderFqcn(string $fqcn): ?string { |
65
|
|
|
$prefix = 'OCA\\TwoFactorGateway\\Provider\\Channel\\Telegram\\Provider\\Drivers\\'; |
66
|
|
|
if (strncmp($fqcn, $prefix, strlen($prefix)) !== 0) { |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
$type = substr($fqcn, strlen($prefix)); |
70
|
|
|
if (strpos($type, '\\') !== false) { |
71
|
|
|
return null; |
72
|
|
|
} |
73
|
|
|
return $type !== '' ? strtolower($type) : null; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|