1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information please see |
17
|
|
|
* <http://phing.info>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Siad Ardroumli <[email protected]> |
22
|
|
|
* @package phing.listener.statistics |
23
|
|
|
*/ |
24
|
|
|
class Table |
25
|
|
|
{ |
26
|
|
|
private $header; |
27
|
|
|
|
28
|
|
|
private $output; |
29
|
|
|
|
30
|
|
|
private $maxLengths; |
31
|
|
|
|
32
|
1 |
|
public function __construct(array $header = [], $rows = 0) |
33
|
|
|
{ |
34
|
1 |
|
$this->header = $header; |
35
|
1 |
|
$columnSize = ($rows >= 0) ? $rows + 1 : 1; |
36
|
1 |
|
$this->output = array_fill(0, $columnSize, array_fill(0, count($this->header), null)); |
37
|
1 |
|
$this->output[0] = $this->header; |
38
|
1 |
|
$this->maxLengths = $this->getHeaderLengths(); |
39
|
1 |
|
} |
40
|
|
|
|
41
|
1 |
|
private function getHeaderLengths() |
42
|
|
|
{ |
43
|
1 |
|
return array_map('strlen', $this->header); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function getMaxLengths() |
47
|
|
|
{ |
48
|
1 |
|
return $this->maxLengths; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function put($x, $y, $value) |
52
|
|
|
{ |
53
|
1 |
|
$this->maxLengths[$y] = $this->max($y, strlen((string) $value)); |
54
|
1 |
|
$this->output[$x][$y] = $value; |
55
|
1 |
|
} |
56
|
|
|
|
57
|
1 |
|
private function max($column, $length) |
58
|
|
|
{ |
59
|
1 |
|
$max = $length; |
60
|
1 |
|
$total = count($this->output); |
61
|
1 |
|
for ($i = 0; $i < $total; $i++) { |
62
|
1 |
|
$valueLength = ($this->output[$i][$column] !== null) ? strlen($this->output[$i][$column]) : 0; |
63
|
1 |
|
$max = max([$max, $valueLength]); |
64
|
|
|
} |
65
|
1 |
|
return $max; |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
public function get($x, $y) |
69
|
|
|
{ |
70
|
1 |
|
return $this->output[$x][$y]; |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
public function rows() |
74
|
|
|
{ |
75
|
1 |
|
return count($this->output); |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
public function columns() |
79
|
|
|
{ |
80
|
1 |
|
return count($this->header); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|