feat: add legacy setting support to ease migration
This commit is contained in:
41
app/Helpers/ArrayHelper.php
Normal file
41
app/Helpers/ArrayHelper.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ArrayHelper
|
||||
{
|
||||
/**
|
||||
* Get value from array using dot notation.
|
||||
*/
|
||||
public static function getValueFromArray(string $key, array $array)
|
||||
{
|
||||
$keys = explode('.', $key);
|
||||
|
||||
foreach ($keys as $segment) {
|
||||
if (!isset($array[$segment])) {
|
||||
return null;
|
||||
}
|
||||
$array = $array[$segment];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function jsonEncodeSafe(mixed $value): string
|
||||
{
|
||||
try {
|
||||
return json_encode(
|
||||
$value,
|
||||
JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
|
||||
);
|
||||
} catch (\JsonException $e) {
|
||||
// Optional: Log the error
|
||||
Log::error("JSON encode failed: " . $e->getMessage());
|
||||
|
||||
// Fallback: return empty object instead of crashing
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user