1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dokuwiki\plugin\issuelinks\classes; |
4
|
|
|
|
5
|
|
|
use dokuwiki\plugin\issuelinks\services\ServiceInterface; |
6
|
|
|
|
7
|
|
|
class ServiceProvider |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
protected static $instance; |
11
|
|
|
protected $serviceClasses = []; |
12
|
|
|
|
13
|
1 |
|
protected function __construct() |
14
|
|
|
{ |
15
|
1 |
|
$serviceDir = __DIR__ . '/../services'; |
16
|
1 |
|
$filenames = scandir($serviceDir, SCANDIR_SORT_ASCENDING); |
17
|
1 |
|
foreach ($filenames as $filename) { |
18
|
1 |
|
if ($filename === '.' || $filename === '..') { |
19
|
1 |
|
continue; |
20
|
|
|
} |
21
|
1 |
|
list($service, $servicePostfix) = explode('.', $filename, 2); |
22
|
1 |
|
if ($servicePostfix !== 'service.php') { |
23
|
1 |
|
continue; |
24
|
|
|
} |
25
|
1 |
|
require_once $serviceDir . '/' . $filename; |
26
|
|
|
|
27
|
1 |
|
$serviceClass = '\\dokuwiki\\plugin\\issuelinks\\services\\' . $service; |
28
|
1 |
|
$this->serviceClasses[$serviceClass::ID] = $serviceClass; |
29
|
|
|
} |
30
|
1 |
|
} |
31
|
|
|
|
32
|
3 |
|
public static function getInstance($forcereload = false) |
33
|
|
|
{ |
34
|
3 |
|
if (null === self::$instance || $forcereload) { |
35
|
1 |
|
self::$instance = new self(); |
36
|
|
|
} |
37
|
3 |
|
return self::$instance; |
38
|
|
|
} |
39
|
|
|
|
40
|
3 |
|
public function getSyntaxKeys() |
41
|
|
|
{ |
42
|
3 |
|
$keys = []; |
43
|
3 |
|
foreach ($this->serviceClasses as $className) { |
44
|
3 |
|
$syntax = $className::SYNTAX; |
45
|
|
|
|
46
|
3 |
|
$keys[$syntax] = $className; |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
return $keys; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return ServiceInterface[] |
54
|
|
|
*/ |
55
|
|
|
public function getWebHookUserAgents() |
56
|
|
|
{ |
57
|
|
|
$userAgents = []; |
58
|
|
|
foreach ($this->serviceClasses as $className) { |
59
|
|
|
$ua = $className::WEBHOOK_UA; |
60
|
|
|
|
61
|
|
|
$userAgents[$ua] = $className; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $userAgents; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return ServiceInterface[]] |
69
|
|
|
*/ |
70
|
|
|
public function getServices() |
71
|
|
|
{ |
72
|
|
|
return $this->serviceClasses; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|