Blame view

vendor/alibabacloud/client/src/Encode.php 999 Bytes
0c34aba8   xu   更新阿里云短信接口
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
<?php

namespace AlibabaCloud\Client;

/**
 * Class Encode
 *
 * @package AlibabaCloud\Client
 */
class Encode
{
    /**
     * @var array
     */
    private $data;

    /**
     * @param array $data
     *
     * @return static
     */
    public static function create(array $data)
    {
        return new static($data);
    }

    /**
     * Encode constructor.
     *
     * @param array $data
     */
    private function __construct(array $data)
    {
        $this->data = $data;
    }

    /**
     * @return bool|string
     */
    public function toString()
    {
        $string = '';
        foreach ($this->data as $key => $value) {
            $encode = rawurlencode($value);
            $string .= "$key=$encode&";
        }

        if (0 < count($this->data)) {
            $string = substr($string, 0, -1);
        }

        return $string;
    }

    /**
     * @return $this
     */
    public function ksort()
    {
        ksort($this->data);

        return $this;
    }
}