<?php
/**
* Bootstrap for JSON sandbox scripts.
*
* Loads and executes JSON payloads containing script definitions.
*/
// Define the directory to look for JSON scripts.
$script_dir = 'scripts/';
// Check if the script directory exists.
if (!is_dir($script_dir)) {
die("Error: Script directory '$script_dir' not found.");
}
// Get a list of JSON files in the script directory.
$json_files = glob($script_dir . '*.json');
// Iterate through each JSON file.
foreach ($json_files as $json_file) {
// Read the JSON file.
$json_data = file_get_contents($json_file);
// Decode the JSON data.
$scripts = json_decode($json_data, true);
// Check if decoding was successful.
if ($scripts === null) {
error_log("Error decoding JSON in '$json_file'.");
continue;
}
// Execute each script.
if (is_array($scripts)) {
foreach ($scripts as $script) {
if (is_string($script['script'])) {
// Execute the script.
eval($script['script']);
} else {
error_log("Error: 'script' field must be a string in '$json_file'.");
}
}
} else {
error_log("Error: JSON in '$json_file' must be an array.");
}
}
?>
Add your comment