Skip to content

Commit

Permalink
fix non string values
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Feb 8, 2025
1 parent a1483b6 commit eec16a2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Drivers/PhpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function toFile(array $values): string
}

/**
* @param array<array-key, mixed> $items
* @param array<array-key, scalar|scalar[]> $items
*/
public function recursiveToFile(
array $items,
Expand All @@ -140,24 +140,29 @@ public function recursiveToFile(
$output = '';

foreach ($items as $key => $value) {

if (is_string($key)) {
$key = str_replace('\"', '"', addslashes($key));
}

if (is_array($value)) {
$value = $this->recursiveToFile($value, $prefix.' ');

if (is_string($key)) {
$key = str_replace('\"', '"', addslashes($key));

$output .= "\n{$prefix} '{$key}' => [{$value}\n {$prefix}],";
} else {
$output .= "\n{$prefix} [{$value}\n {$prefix}],";
}
} else {
$value = str_replace('\"', '"', addslashes($value));

if (is_string($value)) {
$value = "'".str_replace('\"', '"', addslashes($value))."'";
}

if (is_string($key)) {
$key = str_replace('\"', '"', addslashes($key));
$output .= "\n{$prefix} '{$key}' => '{$value}',";
$output .= "\n{$prefix} '{$key}' => {$value},";
} else {
$output .= "\n{$prefix} '{$value}',";
$output .= "\n{$prefix} {$value},";
}
}
}
Expand Down

0 comments on commit eec16a2

Please sign in to comment.