|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Kint_Parser_Table extends Kint_Parser_Plugin |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public function getTypes() |
|
6
|
|
|
{ |
|
7
|
|
|
return array('array'); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
public function getTriggers() |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
return Kint_Parser::TRIGGER_SUCCESS; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function parse(&$var, Kint_Object &$o, $trigger) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
if (empty($o->value->contents)) { |
|
18
|
|
|
return; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$array = $this->parser->getCleanArray($var); |
|
22
|
|
|
|
|
23
|
|
|
if (count($array) < 2) { |
|
24
|
|
|
return; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
// Ensure this is an array of arrays and that all child arrays have the |
|
28
|
|
|
// same keys. We don't care about their children - if there's another |
|
29
|
|
|
// "table" inside we'll just make another one down the value tab |
|
30
|
|
|
$keys = null; |
|
31
|
|
|
foreach ($array as $elem) { |
|
32
|
|
|
if (!is_array($elem) || count($elem) < 2) { |
|
33
|
|
|
return; |
|
34
|
|
|
} elseif ($keys === null) { |
|
35
|
|
|
$keys = array_keys($elem); |
|
36
|
|
|
} elseif (array_keys($elem) !== $keys) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Ensure none of the child arrays are recursion or depth limit. We |
|
42
|
|
|
// don't care if their children are since they are the table cells |
|
43
|
|
|
foreach ($o->value->contents as $childarray) { |
|
44
|
|
|
if (empty($childarray->value->contents)) { |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Objects by reference for the win! We can do a copy-paste of the value |
|
50
|
|
|
// representation contents and just slap a new hint on there and hey |
|
51
|
|
|
// presto we have our table representation with no extra memory used! |
|
52
|
|
|
$table = new Kint_Object_Representation('Table'); |
|
53
|
|
|
$table->contents = $o->value->contents; |
|
54
|
|
|
$table->hints[] = 'table'; |
|
55
|
|
|
$o->addRepresentation($table, 0); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.