From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Db/Branch/BranchSettings.php | 121 ++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 library/Director/Db/Branch/BranchSettings.php (limited to 'library/Director/Db/Branch/BranchSettings.php') diff --git a/library/Director/Db/Branch/BranchSettings.php b/library/Director/Db/Branch/BranchSettings.php new file mode 100644 index 0000000..b3fd164 --- /dev/null +++ b/library/Director/Db/Branch/BranchSettings.php @@ -0,0 +1,121 @@ + $value) { + if (! static::propertyIsBranchSpecific($key)) { + if (is_resource($value)) { + $value = stream_get_contents($value); + } + if ($value !== null && static::propertyIsEncodedArray($key)) { + $value = Json::decode($value); + } + if ($value !== null && static::propertyIsRelatedSet($key)) { + // TODO: We might want to combine them (current VS branched) + $value = Json::decode($value); + } + if ($value !== null && static::propertyIsEncodedDictionary($key)) { + $value = Json::decode($value); + } + if ($value !== null) { + $normalized[$key] = $value; + } + } + } + static::flattenEncodedDicationaries($row); + if (isset($row['set_null'])) { + foreach (Json::decode($row['set_null']) as $property) { + $normalized[$property] = null; + } + } + foreach (self::BRANCH_BOOLEANS as $key) { + if ($row[$key] === 'y') { + $row[$key] = true; + } elseif ($row[$key] === 'n') { + $row[$key] = false; + } else { + throw new \RuntimeException(sprintf( + "Boolean DB property expected, got '%s' for '%s'", + $row[$key], + $key + )); + } + } + + return $normalized; + } + + public static function flattenProperty(array &$properties, $property) + { + // TODO: dots in varnames -> throw or escape? + if (isset($properties[$property])) { + foreach ((array) $properties[$property] as $key => $value) { + $properties["$property.$key"] = $value; + } + unset($properties[$property]); + } + } +} -- cgit v1.2.3