LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_tools.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21{
27 static public bool $use_var_dump = false;
28
36 static public function use_var_dump(bool $bUseVarDump=true): void
37 {
38 self::$use_var_dump = $bUseVarDump;
39 }
40
65 static function display(
66 mixed $something_to_display ="",
67 string $tag="pre",
68 string|null $css_class = null,
69 bool|null $useVarDump = null
70 ): string
71 {
72 if (is_null($something_to_display))
73 {
74 $something_to_display = "The value is NULL!";
75 }
76
77 // [0] useVarDump?
78 $useVarDumpParam = is_bool($useVarDump)
79 ? (bool)$useVarDump
80 : false
81 ;
82
83 $sReturnVal = "\n<".$tag.(null === $css_class ? "" : " class='".$css_class."'").">\n";
84 ob_start();
85 ((true === self::$use_var_dump) || (true === $useVarDumpParam))
86 ? var_dump($something_to_display)
87 : print_r($something_to_display)
88 ;
89 $sReturnVal .= ob_get_clean();
90 $sReturnVal .= "\n</".$tag.">\n";
91
92 return $sReturnVal;
93 }
94
121 static function display_dev(
122 mixed $something_to_display = "",
123 string $tag = "pre",
124 string|null $css_class = null,
125 bool|null $useVarDump = null
126 ): string
127 {
128 if (is_null($something_to_display))
129 {
130 $something_to_display = "The value is NULL!";
131 }
132 // [0] useVarDump?
133 $useVarDumpParam = is_bool($useVarDump)
134 ? (bool)$useVarDump
135 : false
136 ;
137
138 // [1] get 'caller'
139 $backtrace = debug_backtrace();
140 $sOriginInfo = "<none>";
141 if (isset($backtrace[0]['file']))
142 {
143 $sFormated = "<b>Location: %s ->Line %s</b>\n<br>";
144 $sOriginInfo = sprintf(
145 $sFormated,
146 str_replace(LEPTON_PATH, "~", $backtrace[0]['file']),
147 $backtrace[0]['line']
148 );
149
150 }
151 // [2] start return string
152 $s = "\n<".$tag.(null === $css_class ? "" : " class='".$css_class."'").">\n";
153 $s .= $sOriginInfo;
154 ob_start();
155 ((true === self::$use_var_dump) || (true === $useVarDumpParam))
156 ? var_dump($something_to_display)
157 : print_r($something_to_display)
158 ;
159 $s .= ob_get_clean();
160 $s .= "\n</".$tag.">\n";
161
162 return $s;
163 }
164
178 // create signature image
179 static function base64ToImage(string $base64_string, string $output_file): string
180 {
181 $file = fopen($output_file, "wb"); // write binary!
182
183 $data = explode(',', $base64_string);
184
185 fwrite($file, base64_decode($data[1]));
186 fclose($file);
187
188 return $output_file;
189 }
190}
static display(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
static display_dev(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
static use_var_dump(bool $bUseVarDump=true)
static bool $use_var_dump
static base64ToImage(string $base64_string, string $output_file)