RobDWaller / ReallySimpleJWT
1
<?php
2

3
namespace ReallySimpleJWT;
4

5
use ReallySimpleJWT\Interfaces\Decode as DecodeInterface;
6
use ReallySimpleJWT\Helper\Base64;
7
use ReallySimpleJWT\Helper\JsonEncoder;
8

9
/**
10
 * Class to decode a JWT header or payload from a Base64Url string to an
11
 * associative array.
12
 */
13
class Decode implements DecodeInterface
14
{
15
    use Base64;
16
    use JsonEncoder;
17

18
    /**
19
     * Decode a Base64 Url string to a json string
20
     */
21 16
    private function urlDecode(string $toDecode): string
22
    {
23 16
        return (string) base64_decode(
24 16
            $this->addPadding($this->toBase64($toDecode)),
25 16
            true
26
        );
27
    }
28

29
    /**
30
     * Decode a JSON string to an associative array.
31
     *
32
     * @return mixed[]
33
     */
34 16
    public function decode(string $toDecode): array
35
    {
36 16
        return $this->jsonDecode($this->urlDecode($toDecode));
37
    }
38
}

Read our documentation on viewing source code .

Loading