|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kint\Object; |
|
4
|
|
|
|
|
5
|
|
|
use Kint\Object\Representation\Representation; |
|
6
|
|
|
|
|
7
|
|
|
class BasicObject |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
const ACCESS_NONE = null; |
|
10
|
|
|
const ACCESS_PUBLIC = 1; |
|
11
|
|
|
const ACCESS_PROTECTED = 2; |
|
12
|
|
|
const ACCESS_PRIVATE = 3; |
|
13
|
|
|
|
|
14
|
|
|
const OPERATOR_NONE = null; |
|
15
|
|
|
const OPERATOR_ARRAY = 1; |
|
16
|
|
|
const OPERATOR_OBJECT = 2; |
|
17
|
|
|
const OPERATOR_STATIC = 3; |
|
18
|
|
|
|
|
19
|
|
|
public $name; |
|
20
|
|
|
public $type; |
|
21
|
|
|
public $static = false; |
|
22
|
|
|
public $const = false; |
|
23
|
|
|
public $access = self::ACCESS_NONE; |
|
24
|
|
|
public $owner_class; |
|
|
|
|
|
|
25
|
|
|
public $access_path; |
|
|
|
|
|
|
26
|
|
|
public $operator = self::OPERATOR_NONE; |
|
27
|
|
|
public $reference = false; |
|
28
|
|
|
public $size = null; |
|
29
|
|
|
public $depth = 0; |
|
30
|
|
|
public $value = null; |
|
31
|
|
|
public $hints = array(); |
|
32
|
|
|
|
|
33
|
|
|
protected $representations = array(); |
|
34
|
|
|
|
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function addRepresentation(Representation $rep, $pos = null) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
if (isset($this->representations[$rep->getName()])) { |
|
42
|
|
|
return false; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if ($pos === null) { |
|
46
|
|
|
$this->representations[$rep->getName()] = $rep; |
|
47
|
|
|
} else { |
|
48
|
|
|
$this->representations = array_merge( |
|
49
|
|
|
array_slice($this->representations, 0, $pos), |
|
50
|
|
|
array($rep->getName() => $rep), |
|
51
|
|
|
array_slice($this->representations, $pos) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return true; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function replaceRepresentation(Representation $rep, $pos = null) |
|
59
|
|
|
{ |
|
60
|
|
|
if ($pos === null) { |
|
61
|
|
|
$this->representations[$rep->getName()] = $rep; |
|
62
|
|
|
} else { |
|
63
|
|
|
$this->removeRepresentation($rep); |
|
64
|
|
|
$this->addRepresentation($rep, $pos); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function removeRepresentation($rep) |
|
69
|
|
|
{ |
|
70
|
|
|
if ($rep instanceof Representation) { |
|
71
|
|
|
unset($this->representations[$rep->getName()]); |
|
72
|
|
|
} elseif (is_string($rep)) { |
|
73
|
|
|
unset($this->representations[$rep]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getRepresentation($name) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
if (isset($this->representations[$name])) { |
|
80
|
|
|
return $this->representations[$name]; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getRepresentations() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->representations; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function clearRepresentations() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->representations = array(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getType() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->type; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getModifiers() |
|
100
|
|
|
{ |
|
101
|
|
|
$out = $this->getAccess(); |
|
102
|
|
|
|
|
103
|
|
|
if ($this->const) { |
|
104
|
|
|
$out .= ' const'; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if ($this->static) { |
|
108
|
|
|
$out .= ' static'; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (strlen($out)) { |
|
112
|
|
|
return ltrim($out); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getAccess() |
|
117
|
|
|
{ |
|
118
|
|
|
switch ($this->access) { |
|
119
|
|
|
case self::ACCESS_PRIVATE: |
|
120
|
|
|
return 'private'; |
|
121
|
|
|
case self::ACCESS_PROTECTED: |
|
122
|
|
|
return 'protected'; |
|
123
|
|
|
case self::ACCESS_PUBLIC: |
|
124
|
|
|
return 'public'; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function getName() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->name; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getOperator() |
|
134
|
|
|
{ |
|
135
|
|
|
if ($this->operator === self::OPERATOR_ARRAY) { |
|
136
|
|
|
return '=>'; |
|
137
|
|
|
} elseif ($this->operator === self::OPERATOR_OBJECT) { |
|
138
|
|
|
return '->'; |
|
139
|
|
|
} elseif ($this->operator === self::OPERATOR_STATIC) { |
|
140
|
|
|
return '::'; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getSize() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->size; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function getValueShort() |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
if ($rep = $this->value) { |
|
154
|
|
|
if ($this->type === 'boolean') { |
|
155
|
|
|
return $rep->contents ? 'true' : 'false'; |
|
156
|
|
|
} elseif ($this->type === 'integer' || $this->type === 'double') { |
|
157
|
|
|
return $rep->contents; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function getAccessPath() |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->access_path; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public static function blank($name = null, $access_path = null) |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
$o = new self(); |
|
|
|
|
|
|
170
|
|
|
$o->name = $name; |
|
171
|
|
|
$o->access_path = $name; |
|
172
|
|
|
if ($access_path) { |
|
|
|
|
|
|
173
|
|
|
$o->access_path = $access_path; |
|
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $o; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function transplant(BasicObject $new) |
|
180
|
|
|
{ |
|
181
|
|
|
$new->name = $this->name; |
|
182
|
|
|
$new->size = $this->size; |
|
183
|
|
|
$new->access_path = $this->access_path; |
|
184
|
|
|
$new->access = $this->access; |
|
185
|
|
|
$new->static = $this->static; |
|
186
|
|
|
$new->const = $this->const; |
|
187
|
|
|
$new->type = $this->type; |
|
188
|
|
|
$new->depth = $this->depth; |
|
189
|
|
|
$new->owner_class = $this->owner_class; |
|
190
|
|
|
$new->operator = $this->operator; |
|
191
|
|
|
$new->reference = $this->reference; |
|
192
|
|
|
$new->value = $this->value; |
|
193
|
|
|
$new->representations += $this->representations; |
|
194
|
|
|
$new->hints = array_merge($this->hints, $new->hints); |
|
195
|
|
|
|
|
196
|
|
|
return $new; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public static function sortByAccess(BasicObject $a, BasicObject $b) |
|
|
|
|
|
|
200
|
|
|
{ |
|
201
|
|
|
static $sorts = array( |
|
202
|
|
|
self::ACCESS_PUBLIC => 1, |
|
203
|
|
|
self::ACCESS_PROTECTED => 2, |
|
204
|
|
|
self::ACCESS_PRIVATE => 3, |
|
205
|
|
|
self::ACCESS_NONE => 4, |
|
206
|
|
|
); |
|
207
|
|
|
|
|
208
|
|
|
return $sorts[$a->access] - $sorts[$b->access]; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
public static function sortByName(BasicObject $a, BasicObject $b) |
|
|
|
|
|
|
212
|
|
|
{ |
|
213
|
|
|
$ret = strnatcasecmp($a->name, $b->name); |
|
214
|
|
|
|
|
215
|
|
|
if ($ret === 0) { |
|
216
|
|
|
return is_int($b->name) - is_int($a->name); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
return $ret; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.