-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.php
More file actions
48 lines (34 loc) · 897 Bytes
/
Copy pathadapter.php
File metadata and controls
48 lines (34 loc) · 897 Bytes
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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016/3/1
* Time: 21:22
*/
class tianqi{
public static function show(){
$today = array('tep'=>28,'wind'=>7,'sun'=>'sunny');
return serialize($today);
}
}
class AdapterTianqi extends tianqi
{
public static function show()
{
$today = parent::show();
$today = unserialize($today);
$today = json_encode($today);
return $today;
}
}
//========客户端调用============
$tq = unserialize(tianqi::show());
echo '温度:'.$tq['tep'].'<br />';
echo '风力'.$tq['wind'].'<br />';
echo 'sun:'.$tq['sun'].'<br />';
//============适配器下json数据格式=============,没有修改旧的类,
$tq = AdapterTianqi::show();
$tq = json_decode($tq);
echo '温度:'.$tq->tep.'<br />';
echo '风力'.$tq->wind.'<br />';
echo 'sun:'.$tq->sun.'<br />';