From b5cbb3f56dee0430f388dcd91bf29ae3bb747b1e Mon Sep 17 00:00:00 2001 From: devdatt Date: Tue, 23 Dec 2025 01:20:10 +0530 Subject: [PATCH] netplan_yaml --- encoder/static.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/encoder/static.php b/encoder/static.php index 3d4719c..be09a0c 100755 --- a/encoder/static.php +++ b/encoder/static.php @@ -164,15 +164,22 @@ function build_interface(array $d, string $key): array function netplan_yaml(array $data, int $indent = 0): string { + $yaml = ''; $pad = str_repeat(' ', $indent); foreach ($data as $key => $value) { - // List (numeric keys) + if ($value instanceof stdClass) { + $yaml .= "{$pad}{$key}: {}\n"; + continue; + } + if (is_array($value) && array_keys($value) === range(0, count($value) - 1)) { foreach ($value as $item) { - if (is_array($item)) { + if ($item instanceof stdClass) { + $yaml .= "{$pad}- {}\n"; + } elseif (is_array($item)) { $yaml .= "{$pad}-\n"; $yaml .= netplan_yaml($item, $indent + 1); } else { @@ -182,14 +189,12 @@ function netplan_yaml(array $data, int $indent = 0): string continue; } - // Mapping if (is_array($value)) { $yaml .= "{$pad}{$key}:\n"; $yaml .= netplan_yaml($value, $indent + 1); continue; } - // Scalar if (is_bool($value)) { $value = $value ? 'true' : 'false'; } @@ -200,6 +205,7 @@ function netplan_yaml(array $data, int $indent = 0): string return $yaml; } + function update_service($which_service) {