16 defined(
'HCE_CLI_READ_FROM_FILE_STATEMENT') or define('HCE_CLI_READ_FROM_FILE_STATEMENT', 'READ_FROM_FILE:');
21 foreach ($argv as $arg) {
22 if (preg_match(
'/--([^=]+)=(.*)/',$arg,$reg)) {
23 $_ARG[$reg[1]] = $reg[2];
24 } elseif(preg_match(
'/-([a-zA-Z0-9])/',$arg,$reg)) {
25 $_ARG[$reg[1]] =
'true';
37 $ends_line_level = NULL;
38 $json_length = strlen(
$json );
40 for( $i = 0; $i < $json_length; $i++ ) {
42 $new_line_level = NULL;
44 if( $ends_line_level !== NULL ) {
45 $new_line_level = $ends_line_level;
46 $ends_line_level = NULL;
48 if( $char ===
'"' && $prev_char !=
'\\' ) {
49 $in_quotes = !$in_quotes;
50 }
else if( ! $in_quotes ) {
54 $ends_line_level = NULL;
55 $new_line_level = $level;
61 $ends_line_level = $level;
68 case " ":
case "\t":
case "\n":
case "\r":
70 $ends_line_level = $new_line_level;
71 $new_line_level = NULL;
75 if( $new_line_level !== NULL ) {
76 $result .= PHP_EOL.str_repeat( $left_ident, $new_line_level );
78 $result .= $char.$post;
86 $ret=array(
'width'=>0,
'height'=>0);
88 preg_match_all(
"/rows.([0-9]+);.columns.([0-9]+);/", strtolower(exec(
'stty -a | grep columns')), $output);
90 if(
sizeof($output) == 3) {
91 $ret[
'width'] = $output[1][0];
92 $ret[
'height'] = $output[2][0];
105 if(!isset($params[
'whitespace_char'])){
107 $params[
'whitespace_char']=
' ';
109 if(!isset($params[
'interrow_ident'])){
111 $params[
'interrow_ident']=0;
113 if(!isset($params[
'hline_char'])){
115 $params[
'hline_char']=
'_';
117 if(!isset($params[
'vline_char'])){
119 $params[
'vline_char']=
'|';
121 if(!isset($params[
'max_width'])){
123 $params[
'max_width']=80;
125 if(!isset($params[
'item_hident'])){
127 $params[
'item_hident']=1;
131 $getMaxItems =
function($arr) use(&$getMaxItems){
134 foreach($arr as $val){
136 $n+=$getMaxItems($val);
145 $maxItemsOnOneLevel=$getMaxItems($array);
148 $getTotalWidth =
function($arr) use(&$getTotalWidth){
151 foreach($arr as $key=>$val){
153 $n+=$getTotalWidth($val);
162 $totalWidth=$getTotalWidth($array);
165 $getMaxLength =
function($arr){
167 $lengths=array_map(
'strlen', $arr);
172 return max($lengths);
176 $params[
'max_space_per_item']=floor(($params[
'max_width']-$totalWidth)/($maxItemsOnOneLevel<1 ? 1 : $maxItemsOnOneLevel))-$params[
'item_hident'];
177 $params[
'max_space_per_item']=($params[
'max_space_per_item']<1) ? 1: $params[
'max_space_per_item'];
180 $getMaxTitleWidth =
function($arr) use(&$getMaxTitleWidth){
183 foreach($arr as $key=>$val){
184 $lines=explode(PHP_EOL, $key);
185 foreach($lines as $line){
186 if(strlen($line)>$maxWidth){
187 $maxWidth=strlen($line);
192 $getMaxTitleWidth($val);
200 $getMaxTitleLines =
function($arr) use(&$getMaxTitleLines){
203 foreach($arr as $key=>$val){
204 $lines=substr_count($key, PHP_EOL)+1;
205 if($lines>$maxLines){
210 $getMaxTitleLines($val);
218 $fixTitleLinesWidth =
function($arr, $titleLines, $titleWidth) use(&$fixTitleLinesWidth){
222 foreach($arr as $key=>$val){
223 $lines=explode(PHP_EOL, $key);
225 foreach($lines as $lineKey=>$line){
226 if(strlen($line)<$titleWidth){
227 $diff=$titleWidth-strlen($line);
228 $lines[$lineKey]=str_repeat(
' ', ceil($diff/2)).$line.str_repeat(
' ', floor($diff/2));
232 for($i=0; $i<$titleLines-count($lines); $i++){
233 $lines[]=str_repeat(
' ', $titleWidth);
236 $ret[implode(PHP_EOL, $lines)]=$fixTitleLinesWidth($val, $titleLines, $titleWidth);
246 $getTreeChartArray =
function($arr, $params, $offset=0) use(&$getTreeChartArray, &$getMaxLength){
263 $vlines=str_repeat($params[
'whitespace_char'], $offset);
264 $hlines=str_repeat($params[
'whitespace_char'], $offset);
265 $vlines2=str_repeat($params[
'whitespace_char'], $offset);
267 foreach($arr as $key=>$val){
268 $lines=explode(PHP_EOL, $key);
270 if(count($titles)==0){
272 foreach($lines as $line){
273 $titles[]=str_repeat($params[
'whitespace_char'], $offset);
277 $lastNodeStrLen=count($ret1)>0 ? $getMaxLength($ret1) : strlen($titles[0]);
279 $ret1=array_merge($ret1, $getTreeChartArray($val, $params, $lastNodeStrLen));
284 $offset1=($lastNodeStrLen-strlen($titles[0]))>0 ? ($lastNodeStrLen-strlen($titles[0])) : $params[
'max_space_per_item'];
287 for($j=0; $j<count($lines); $j++){
288 $titles[$j].=str_repeat($params[
'whitespace_char'], $offset1).$lines[$j];
292 $vline_char=$params[
'vline_char'];
294 $vline_char=$params[
'whitespace_char'];
296 $chars=$offset1+((strlen($lines[0])/2)-1);
300 $vlines.=str_repeat($params[
'whitespace_char'], $chars).$vline_char.str_repeat($params[
'whitespace_char'], ((strlen($lines[0])/2)));
304 $vlines2.=str_repeat($params[
'whitespace_char'], $offset1+((strlen($lines[0])/2)-1)).$params[
'vline_char'].str_repeat($params[
'whitespace_char'], ((strlen($lines[0])/2)));
307 $hlines.=str_repeat($params[
'whitespace_char'], $offset1+(strlen($lines[0])/2)).str_repeat($params[
'hline_char'], strlen($lines[0])/2);
309 $hlines.=str_repeat($params[
'hline_char'], strlen($vlines2)-strlen($hlines)-(strlen($lines[0])/2));
311 $hlines=substr($hlines, 0, strlen($hlines)-1);
322 foreach($titles as $titles_key=>$titles_value){
323 $titles[$titles_key]=rtrim($titles_value);
325 $ret[]=implode(PHP_EOL, $titles);
327 $ret=array_merge($ret, $ret1);
332 $maxTitleWidth=$getMaxTitleWidth($array);
333 if($maxTitleWidth%2>0){
337 $maxTitleLines=$getMaxTitleLines($array);
339 $array=$fixTitleLinesWidth($array, $maxTitleLines, $maxTitleWidth);
341 $res=$getTreeChartArray($array, $params);
344 for($i=0; $i<count($res); $i++){
345 $res[$i]=rtrim($res[$i]);
349 for($i=0; $i<count($res)-1; $i++){
351 while(($p=strpos($res[$i], $params[
'vline_char'], $p))!==
false){
352 if(strlen($res[$i+1])<$p){
353 $res[$i+1].=str_repeat($params[
'whitespace_char'], $p-strlen($res[$i+1])).$params[
'vline_char'];
363 for($i=0; $i<count($res)-1; $i++){
364 if($res[$i]!=$res[$i+1]){
372 }
while($duplicates>0);
374 return implode(PHP_EOL, $new_res);
380 $statement_len=strlen($statement);
382 if(is_string($input)){
383 if(strlen($input)>$statement_len && substr($input, 0, $statement_len)==$statement){
384 $file_name=substr($input, $statement_len);
385 if(file_exists($file_name)){
386 $content=file_get_contents($file_name);
387 $content=@json_decode($content,
true);
390 if(strlen($error_message)>0){
391 $content=$error_message.$file_name;
395 }elseif(is_array($input)){
396 foreach($input as $key=>$val){