This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-descripton.php
93 lines (71 loc) · 2.37 KB
/
create-descripton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
*
* @created 27.07.2019
* @author smiley <smiley@chillerlan.net>
* @copyright 2019 smiley
* @license MIT
*/
use chillerlan\OAuth\Core\{ClientCredentials, OAuth1Interface, OAuth2Interface, OAuthInterface};
/**
* @var \Psr\Http\Client\ClientInterface $http
* @var \chillerlan\Settings\SettingsContainerInterface $options
* @var \Psr\Log\LoggerInterface $logger
*/
require_once __DIR__.'/provider-example-common.php';
const REPLACE_START = '<!-- TABLE-START -->';
const REPLACE_END = '<!-- TABLE_END -->';
$table = [
'| Provider | API keys | revoke access | OAuth | `ClientCredentials` |',
'|----------|----------|---------------|-------|---------------------|',
];
foreach(getProviders(__DIR__.'/../src/Providers') as $p){
/** @var \OAuthProviderFactory $factory */
$provider = $factory->getProvider($p['fqcn'], '', false);
$oauth = match(true){
$provider instanceof OAuth2Interface => '2',
$provider instanceof OAuth1Interface => '1',
default => '-',
};
$table[] = '| ['.$p['name'].']('.$provider->apiDocs.')'.
' | [link]('.$provider->applicationURL.')'.
' | '.((!$provider->userRevokeURL) ? '' : '[link]('.$provider->userRevokeURL.')').
' | '.$oauth.
' | '.(($provider instanceof ClientCredentials) ? '✓' : '').
' |' ;
printf("%s\n", $p['fqcn']);
}
$file = __DIR__.'/../README.md';
$readme = file_get_contents($file);
$start = strpos($readme, REPLACE_START);
$end = (strpos($readme, REPLACE_END) + strlen(REPLACE_END));
$readme = str_replace(
substr($readme, $start, ($end - $start)),
REPLACE_START."\n".implode("\n", $table)."\n".REPLACE_END,
$readme,
);
file_put_contents($file, $readme);
exit;
// @todo
function getProviders(string $providerDir):array{
$providerDir = realpath($providerDir);
$providers = [];
/** @var \SplFileInfo $e */
foreach(new IteratorIterator(new DirectoryIterator($providerDir)) as $e){
if($e->getExtension() !== 'php'){
continue;
}
$class = 'chillerlan\\OAuth\\Providers\\'.substr($e->getFilename(), 0, -4);
try{
$r = new ReflectionClass($class);
if(!$r->implementsInterface(OAuthInterface::class) || $r->isAbstract()){
continue;
}
$providers[hash('crc32b', $r->getShortName())] = ['name' => $r->getShortName(), 'fqcn' => $class];
}
catch(Throwable){
continue;
}
}
return $providers;
}