|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace IonBazan\Bundle\GuzzleBundleAliyunSignerPlugin; |
|
6
|
|
|
|
|
7
|
|
|
use EightPoints\Bundle\GuzzleBundle\PluginInterface; |
|
8
|
|
|
use IonBazan\AliyunSigner\Guzzle\RequestSignerMiddleware; |
|
9
|
|
|
use IonBazan\AliyunSigner\Key; |
|
10
|
|
|
use IonBazan\AliyunSigner\RequestSigner; |
|
11
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
15
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
|
16
|
|
|
|
|
17
|
|
|
class AliyunRequestSignerPlugin extends Bundle implements PluginInterface |
|
18
|
|
|
{ |
|
19
|
|
|
public function getPluginName(): string |
|
20
|
|
|
{ |
|
21
|
|
|
return 'aliyun_signer'; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function addConfiguration(ArrayNodeDefinition $pluginNode): void |
|
25
|
|
|
{ |
|
26
|
|
|
$pluginNode |
|
27
|
|
|
->addDefaultsIfNotSet() |
|
28
|
|
|
->children() |
|
29
|
|
|
->scalarNode('app_id')->defaultNull()->end() |
|
30
|
|
|
->scalarNode('secret')->defaultNull()->end() |
|
|
|
|
|
|
31
|
|
|
->end(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
35
|
|
|
{ |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function loadForClient( |
|
39
|
|
|
array $config, |
|
40
|
|
|
ContainerBuilder $container, |
|
41
|
|
|
string $clientName, |
|
42
|
|
|
Definition $handler |
|
43
|
|
|
): void { |
|
44
|
|
|
if ($config['app_id'] && $config['secret']) { |
|
45
|
|
|
$key = new Definition(Key::class); |
|
46
|
|
|
$key->setArguments([$config['app_id'], $config['secret']]); |
|
47
|
|
|
$keyId = sprintf('guzzle_bundle_aliyun_signer_plugin.key.%s', $clientName); |
|
48
|
|
|
$container->setDefinition($keyId, $key); |
|
49
|
|
|
|
|
50
|
|
|
$signer = new Definition(RequestSigner::class); |
|
51
|
|
|
$signer->setArguments([new Reference($keyId)]); |
|
52
|
|
|
$signerId = sprintf('guzzle_bundle_aliyun_signer_plugin.signer.%s', $clientName); |
|
53
|
|
|
$container->setDefinition($signerId, $signer); |
|
54
|
|
|
|
|
55
|
|
|
$middleware = new Definition(RequestSignerMiddleware::class); |
|
56
|
|
|
$middleware->setArguments([new Reference($signerId)]); |
|
57
|
|
|
$middlewareId = sprintf('guzzle_bundle_aliyun_signer_plugin.middleware.%s', $clientName); |
|
58
|
|
|
$container->setDefinition($middlewareId, $middleware); |
|
59
|
|
|
|
|
60
|
|
|
$handler->addMethodCall('unshift', [new Reference($middlewareId), $this->getPluginName()]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|