1 | <?php |
||
2 | require_once __DIR__ .'/../vendor/autoload.php'; |
||
3 | use Kristuff\Mishell\Console; |
||
4 | |||
5 | console::resetDefaults(); |
||
6 | |||
7 | Console::log(' ' . Console::text('Basic sample', 'white', 'underlined')); |
||
8 | Console::log(); |
||
9 | |||
10 | $rowHeaders = ['Index' => 10, 'Item' => 25, 'Description' => 50]; |
||
11 | $rows = [ |
||
12 | ['foo', 'some text for foo'], |
||
13 | ['bar', 'some text for bar'], |
||
14 | ['foobar', 'some text for foobar'] |
||
15 | ]; |
||
16 | Console::log(Console::tableSeparator($rowHeaders)); |
||
17 | Console::log(Console::tableRow($rowHeaders)); |
||
18 | Console::log(Console::tableRowSeparator($rowHeaders)); |
||
19 | |||
20 | foreach ($rows as $key => $value){ |
||
21 | Console::log(Console::tableRow([ |
||
22 | $key => 10, |
||
23 | $rows[$key][0] => 25, |
||
24 | $rows[$key][1] => 50 |
||
25 | ])); |
||
26 | } |
||
27 | Console::log(Console::tableSeparator($rowHeaders)); |
||
28 | |||
29 | Console::log(); |
||
30 | Console::log(); |
||
31 | |||
32 | |||
33 | |||
34 | // ------------------------------- |
||
35 | // ------ ADVANCED SAMPLE -------- |
||
36 | // ------------------------------- |
||
37 | Console::log(' ' . Console::text('Advanced sample', 'white', 'underlined')); |
||
38 | Console::log(); |
||
39 | |||
40 | $rowHeaders = [ |
||
41 | Console::text('Index', 'blue') => 10, |
||
42 | Console::text('Item', 'white', 'underlined') => 25, |
||
43 | Console::text('Description', 'white') => 50 |
||
44 | ]; |
||
45 | $rows = [ |
||
46 | [ |
||
47 | Console::text('foo', 'white'), |
||
48 | Console::text('some centered text red for foo', 'red') |
||
49 | ], |
||
50 | [ |
||
51 | Console::text('bar', 'white'), |
||
52 | Console::text( 'some centered text green for bar', 'green') |
||
53 | ], |
||
54 | [ |
||
55 | Console::text('foobar', 'white'), |
||
56 | 'some text with unicode ✓ ' .Console::text('on BLUE here', 'white', 'blue') |
||
57 | ] |
||
58 | ]; |
||
59 | |||
60 | |||
61 | |||
62 | //Console::$verticalSeparator = '!'; // change the vertical separator |
||
63 | //Console::$verticalInnerSeparator = '!'; // change the vertical inner separator |
||
64 | //Console::$horizontalSeparator = '_'; // change the horizontal separator |
||
65 | |||
66 | Console::$tableCellPadding = ' '; // increase cell padding to 2 white chars (default is 1) |
||
67 | |||
68 | // table start |
||
69 | Console::log(Console::tableSeparator($rowHeaders)); // top line |----------------------- ... |
||
70 | Console::log(Console::tableRow($rowHeaders)); // columns headers | foo | bar |--- ... |
||
71 | Console::log(Console::tableRowSeparator($rowHeaders)); // saparator |---------|---------|--- ... |
||
72 | Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
||
73 | |||
74 | // tables rows |
||
75 | foreach ($rows as $key => $value){ |
||
76 | |||
77 | Console::log( |
||
78 | Console::TableRowStart(). // start row with separator. Then, each cell will end with a separator |
||
79 | Console::TableRowCell($key, 10). //no align => default is left |
||
80 | Console::TableRowCell($rows[$key][0] , 25, Console::ALIGN_RIGHT). //set align right |
||
81 | Console::TableRowCell($rows[$key][1] , 50, Console::ALIGN_CENTER) //set align center |
||
82 | ); |
||
83 | } |
||
84 | |||
85 | // table end |
||
86 | Console::log(Console::tableRowEmpty($rowHeaders)); // empty row | | | ... |
||
87 | Console::log(Console::tableSeparator($rowHeaders)); // saparator |----------------------- ... |
||
88 | console::resetDefaults(); |
||
89 | |||
90 | // ------------------------------- |
||
91 | // ------ ANOTHER STYLE --------- |
||
92 | // ------------------------------- |
||
93 | Console::log(); |
||
94 | Console::log(' ' . Console::text('Another style sample', 'white', 'underlined')); |
||
95 | Console::log(); |
||
96 | |||
97 | $rowHeaders = [ |
||
98 | Console::text('Item', 'darkgray') => 10, |
||
99 | Console::text('Status', 'darkgray') => 12, |
||
100 | Console::text('Description', 'darkgray') => 25 |
||
101 | ]; |
||
102 | $rows = [ |
||
103 | [Console::text('foo', 'white'), Console::text(' ONLINE ', 'white', 'green') , Console::text('some text for foo', 'white')], |
||
104 | [Console::text('bar', 'white'), Console::text(' ONLINE ', 'white', 'green') , Console::text('some text for bar', 'white')], |
||
105 | [Console::text('foobar ', 'white'), Console::text(' OFFLINE ', 'white', 'red') , Console::text('some text for foobar', 'white')] |
||
106 | ]; |
||
107 | |||
108 | Console::$horizontalSeparator = '-'; // change the horizontal separator |
||
109 | Console::$tableCellPadding = ''; // no padding |
||
110 | Console::$verticalInnerSeparator = ' '; // blank separator |
||
111 | Console::$verticalSeparator = ' '; // no top left/right separator except a margin.. |
||
112 | // Console::$verticalHeaderSeparator = ''; // no top left/right separator (not needed) |
||
113 | |||
114 | // table start |
||
115 | Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- --- |
||
116 | Console::log(Console::tableRow($rowHeaders, 'drakgray')); // columns headers foo bar f... |
||
117 | Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- --- |
||
118 | |||
119 | // tables rows |
||
120 | foreach ($rows as $row){ |
||
121 | Console::log( |
||
122 | Console::TableRowStart(). // start row with separator. Then, each cell will end with a separator |
||
123 | Console::TableRowCell($row[0] , 10). // keep left alignment |
||
124 | Console::TableRowCell($row[1] , 12, Console::ALIGN_CENTER). // align center |
||
125 | Console::TableRowCell($row[2] , 25) // keep left alignment |
||
126 | ); |
||
127 | } |
||
128 | // table end |
||
129 | Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- --- |
||
130 | console::resetDefaults(); |
||
131 | |||
132 | ?> |
||
0 ignored issues
–
show
|
|||
133 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.