笔记9:适配器模式

// 服务端代码
class tianqi
{
    public static function show()
    {
        $today = ['tep' => 28, 'wind' => 7, 'sun' => 'sunny'];
        return serialize($today);
    }
}

class AdapterTianqi extends tianqi
{
    public static function show()
    {
        $today = parent::show();
        $today = unserialize($today);
        return json_encode($today);
    }
}

//// 客户端调用(非适配器方式)
//$tq = tianqi::show();
//$tq = unserialize($tq);
//echo '温度:' . $tq['tep'], "\n";
//echo '风力:' . $tq['wind'], "\n";
//echo 'sun:' . $tq['sun'], "\n";

// 客户端调用
$tq = AdapterTianqi::show();
$tq = json_decode($tq, true);
echo '温度:' . $tq['tep'], "\n";
echo '风力:' . $tq['wind'], "\n";
echo 'sun:' . $tq['sun'], "\n";