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 0
/
Copy pathcreate-docblocks.php
73 lines (58 loc) · 2.2 KB
/
create-docblocks.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
<?php
/**
*
* @filesource create-docblocks.php
* @created 27.07.2019
* @author smiley <smiley@chillerlan.net>
* @copyright 2019 smiley
* @license MIT
*/
namespace chillerlan\OAuthExamples;
use chillerlan\OAuthTest\MagicAPI\EndpointDocblock;
use chillerlan\OAuth\Core\{ClientCredentials, OAuth1Interface, OAuth2Interface};
use Psr\Http\Message\ResponseInterface;
use function chillerlan\OAuth\Providers\getProviders;
use function file_get_contents, file_put_contents, implode, str_replace, strpos, substr;
use const PHP_EOL;
$ENVVAR = '';
require_once __DIR__.'/provider-example-common.php';
/**
* @var \Psr\Http\Client\ClientInterface $http
* @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage
* @var \chillerlan\Settings\SettingsContainerInterface $options
* @var \Psr\Log\LoggerInterface $logger
*/
$table = [
' Provider | API keys | revoke access | OAuth | `ClientCredentials`',
'----------|----------|---------------|-------|--------------------',
];
foreach(getProviders() as $p){
/** @var \chillerlan\OAuth\Core\OAuthInterface $provider */
$provider = new $p['fqcn']($http, $storage, $options, $logger);
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
$doc = new EndpointDocblock($provider, $provider->endpoints);
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
$doc->create(ResponseInterface::class);
# $doc->createInterface($p['name'], ResponseInterface::class);
# $doc->createJSON();
switch(true){
case $provider instanceof OAuth2Interface:
$oauth = '2';
break;
case $provider instanceof OAuth1Interface:
$oauth = '1';
break;
default:
$oauth = '-';
}
$table[] = '['.$p['name'].']('.$provider->apiDocs.')'.
' | [link]('.$provider->applicationURL.')'.
' | '.(!$provider->userRevokeURL ? '' : '[link]('.$provider->userRevokeURL.')').
' | '.$oauth.
' | '.($provider instanceof ClientCredentials ? '✓' : '');
}
$file = __DIR__.'/../README.md';
$readme = file_get_contents($file);
$start = strpos($readme, '<!--A-->') + 8;
$end = strpos($readme, '<!--O-->');
file_put_contents($file, str_replace(substr($readme, $start, $end - $start), PHP_EOL.implode(PHP_EOL, $table).PHP_EOL, $readme));