-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsnao.php
More file actions
111 lines (96 loc) · 2.43 KB
/
Copy pathjsnao.php
File metadata and controls
111 lines (96 loc) · 2.43 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?
/*
* 取材自網友 http://bbs.phpchina.com/thread-123682-1-1.html
*/
include_once 'jsnao_inputype.php';
class Jsnao extends ArrayObject
{
protected $version = "1.1.4";
/**
* 獲取 ArrayObject 因子
* @param mix $mix 可輸入的型態或資料格式 string | integer | array | object | json | NULL
*/
public function __construct($mix = null)
{
$array = Jsnao_inputype::filter($mix);
foreach ($array as &$value)
{
is_array($value) && $value = new self($value);
}
parent::__construct($array);
}
public function version ()
{
return $this->version;
}
// 取值
public function __get($index)
{
return $this->get($index);
}
// 賦值
public function __set($index, $value)
{
$this->put($index, $value);
}
// 是否存在
public function __isset($index)
{
return $this->offsetExists($index);
}
// 刪除
public function __unset($index)
{
$this->offsetUnset($index);
}
// 轉換為陣列類型
public function toArray()
{
$array = $this->getArrayCopy();
foreach ($array as &$value)
{
($value instanceof self) && $value = $value->toArray();
}
return $array;
}
// 輸出成字串
public function __toString()
{
return var_export($this->toArray(), true);
}
// 輸出到 JavaScript console.log,回傳 $this 可供串接
public function log($title = NULL)
{
$string = $this->__toString();
if ($title !== NULL)
{
$this->console_log("'§ -------- {$title} -------- §'", false);
}
$this->console_log($string, true);
if ($title !== NULL)
{
$this->console_log("' '", false);
}
return $this;
}
private function console_log($string, $isencode = false)
{
if ($isencode == true)
{
$string = json_encode($this->toArray());
}
echo "<script>console.log({$string})</script>";
}
// 根據索引賦值
public function put($index, $value)
{
is_array($value) && $value = new self($value);
return $this->offsetSet($index, $value);
}
// 根據索引取值
public function get($index)
{
return $this->offsetGet($index);
}
}
?>