Blame view

vendor/alibabacloud/client/src/Credentials/Ini/OptionsTrait.php 2.87 KB
310f6425   曹明   1.完善短信提示“提取码”功能。
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php

namespace AlibabaCloud\Client\Credentials\Ini;

use AlibabaCloud\Client\Clients\Client;
use AlibabaCloud\Client\Exception\ClientException;

/**
 * Trait OptionsTrait
 *
 * @package   AlibabaCloud\Client\Credentials\Ini
 *
 * @mixin     IniCredential
 */
trait OptionsTrait
{
    /**
     * @param array  $configures
     * @param Client $client
     *
     * @throws ClientException
     */
    private static function setClientAttributes($configures, Client $client)
    {
        if (self::isNotEmpty($configures, 'region_id')) {
            $client->regionId($configures['region_id']);
        }

        if (isset($configures['debug'])) {
            $client->options(
                [
                    'debug' => (bool)$configures['debug'],
                ]
            );
        }

        if (self::isNotEmpty($configures, 'timeout')) {
            $client->options(
                [
                    'timeout' => $configures['timeout'],
                ]
            );
        }

        if (self::isNotEmpty($configures, 'connect_timeout')) {
            $client->options(
                [
                    'connect_timeout' => $configures['connect_timeout'],
                ]
            );
        }
    }

    /**
     * @param array  $configures
     * @param Client $client
     */
    private static function setProxy($configures, Client $client)
    {
        if (self::isNotEmpty($configures, 'proxy')) {
            $client->options(
                [
                    'proxy' => $configures['proxy'],
                ]
            );
        }
        $proxy = [];
        if (self::isNotEmpty($configures, 'proxy_http')) {
            $proxy['http'] = $configures['proxy_http'];
        }
        if (self::isNotEmpty($configures, 'proxy_https')) {
            $proxy['https'] = $configures['proxy_https'];
        }
        if (self::isNotEmpty($configures, 'proxy_no')) {
            $proxy['no'] = \explode(',', $configures['proxy_no']);
        }
        if ($proxy !== []) {
            $client->options(
                [
                    'proxy' => $proxy,
                ]
            );
        }
    }

    /**
     * @param array  $configures
     * @param Client $client
     */
    private static function setCert($configures, Client $client)
    {
        if (self::isNotEmpty($configures, 'cert_file') && !self::isNotEmpty($configures, 'cert_password')) {
            $client->options(
                [
                    'cert' => $configures['cert_file'],
                ]
            );
        }

        if (self::isNotEmpty($configures, 'cert_file') && self::isNotEmpty($configures, 'cert_password')) {
            $client->options(
                [
                    'cert' => [
                        $configures['cert_file'],
                        $configures['cert_password'],
                    ],
                ]
            );
        }
    }
}