|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakePHPify : CakePHP Plugin for Shopify API Authentication |
|
4
|
|
|
* Copyright (c) Multidimension.al (http://multidimension.al) |
|
5
|
|
|
* Github : https://github.com/multidimension-al/cakephpify |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under The MIT License |
|
8
|
|
|
* For full copyright and license information, please see the LICENSE file |
|
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright (c) Multidimension.al (http://multidimension.al) |
|
12
|
|
|
* @link https://github.com/multidimension-al/cakephpify CakePHPify Github |
|
13
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Multidimensional\Cakephpify\Shell\Helper; |
|
17
|
|
|
|
|
18
|
|
|
use Cake\Console\Helper; |
|
19
|
|
|
use Cake\Console\Shell; |
|
20
|
|
|
|
|
21
|
|
|
class TableHelper extends Helper |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param array $data array of data to be displayed |
|
26
|
|
|
* @param int $columns maximum number of table columns |
|
27
|
|
|
* @param int $terminalWidth maximum table width in characters1 |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function output($data, $columns = 10, $terminalWidth = 80) |
|
31
|
|
|
{ |
|
32
|
|
|
$dataCount = count($data); |
|
33
|
|
|
while ($dataCount % $columns != 0 && $columns > 5) { |
|
34
|
|
|
$columns--; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$maxLength = max(array_map('strlen', $data)); |
|
38
|
|
|
|
|
39
|
|
|
while (((($columns * ($maxLength + 3)) + 3) > $terminalWidth) && ($columns >= 1)) { |
|
40
|
|
|
$columns--; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$this->_io->out(' ' . str_repeat('+-' . str_repeat('-', $maxLength) . '-', $columns) . '+ '); |
|
44
|
|
|
|
|
45
|
|
|
$dataCount = count($data); |
|
46
|
|
|
for ($i = 0; $i < $dataCount;) { |
|
47
|
|
|
$output = ' '; |
|
48
|
|
|
$j = $i; |
|
|
|
|
|
|
49
|
|
|
for ($k = $i; $k < ($columns + $j); $k++) { |
|
50
|
|
|
if (!isset($data[$i])) { |
|
51
|
|
|
$data[$i] = ''; |
|
52
|
|
|
} |
|
53
|
|
|
$output .= '| ' . str_repeat(' ', floor(($maxLength - strlen($data[$i])) / 2)) . $data[$i] . str_repeat(' ', ceil(($maxLength - strlen($data[$i])) / 2)) . ' '; |
|
54
|
|
|
$i++; |
|
55
|
|
|
} |
|
56
|
|
|
$this->_io->out($output . '|'); |
|
57
|
|
|
$this->_io->out(' ' . str_repeat('+-' . str_repeat('-', $maxLength) . '-', $columns) . '+ '); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.