<?php
/**
 * Link         :   http://www.phpcorner.net
 * User         :   qingbing<780042175@qq.com>
 * Date         :   2018-10-27
 * Version      :   1.0
 */

namespace Test;

use Helper\Coding;
use TestCore\Tester;

class TestCoding extends Tester
{
    /**
     * 执行函数
     * @return mixed|void
     */
    public function run()
    {
        $sourceString = "This is a coding-test.";
        $sourceArray = [
            "homepage" => "http://www.phpcorner.net",
            "authors" => [
                "name" => "qingbing",
                "email" => "780042175@qq.com",
                "description" => "中文描述"
            ],
        ];
        var_dump($sourceString);
        var_dump($sourceArray);
        // base64 编码
        var_dump("=== base64 : 只能针对字符串 ===");
        $codingString = Coding::base64_encode($sourceString);
        $decodingString = Coding::base64_decode($codingString);
        var_dump($codingString);
        var_dump($decodingString);

        // secure
        var_dump("=== secure ：可以是任意变量，其实也是base64 ===");
        $codingString = Coding::secure_encode($sourceArray);
        $decodingString = Coding::secure_decode($codingString);
        var_dump($codingString);
        var_dump($decodingString);

        // json
        var_dump("=== json : 系统函数 ===");
        $codingString = Coding::json_encode($sourceArray);
        $decodingString = Coding::json_decode($codingString);
        var_dump($codingString);
        var_dump($decodingString);

        var_dump("=== json : 自定义函数 ===");
        $codingString = Coding::json_encode($sourceArray, true);
        $decodingString = Coding::json_decode($codingString);
        var_dump($codingString);
        var_dump($decodingString);
    }
}