Skip to content

Commit

Permalink
Allow no header
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadyita committed Mar 1, 2024
1 parent 505401a commit b61502a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ public static function import(string $in): mixed {
return $vars;
}

public static function export(mixed $in): string {
public static function export(mixed $in, bool $noHeader=false): string {
$header = '';
if ($noHeader === false) {
$header = '<?' . 'php' . PHP_EOL . PHP_EOL.
'declare(script_types=1);' . PHP_EOL . PHP_EOL;
}
if (!is_array($in) || Utils::arrayIsList($in)) {
return VarExporter::export($in);
return $header . VarExporter::export($in);
}
$blocks = [];
foreach ($in as $key => $value) {
$blocks []= "\$vars[" . VarExporter::export($key) . "] = ".
VarExporter::export($value) . ";\n";
}
return join("", $blocks);
return $header . join("", $blocks);
}
}

0 comments on commit b61502a

Please sign in to comment.