/** * Utility function to overwrite object keys and support multiple levels. * array_merge() overwrites keys, but isn't recursive. * array_merge_recursive() is recursive but doesn't overwrite deeper levels, * and merges by creating arrays, instead of overwriting them. * * @since 1.0.0 * @param $obj1 object: Starting point * @param $obj2 object: Values from this object are added * @param $options array: one or more of 'add', 'overwrite'. * Defaults to array( 'add', 'overwrite' ); If neither option is given, the function * will effectively be a no-op. */ function object_merge($obj1, $obj2, $options = null) { $options = is_array($options) ? $options : array('add', 'overwrite'); foreach ($obj2 as $key => $val) { if (property_exists($obj1, $key) && in_array('overwrite', $options)) { if (is_object($val)) { $obj1->{$key} = object_merge($obj1->{$key}, $obj2->{$key}, $options); } else { $obj1->{$key} = $val; } } elseif (!property_exists($obj1, $key) && in_array('add', $options)) { $obj1->{$key} = $val; } } return $obj1; }
} if (!is_readable($localSettingsFile)) { echo "<b>TestSwarm Fatal:</b> Not readable: {$localSettingsFile}\n"; exit; } $defaultSettings = json_decode(file_get_contents($defaultSettingsFile)); $localSettings = json_decode(file_get_contents($localSettingsFile)); if (!$defaultSettings) { echo "<b>TestSwarm Fatal:</b> Default settings file contains invalid JSON.\n"; exit; } if (!$localSettings) { echo "<b>TestSwarm Fatal:</b> Local settings file contains invalid JSON.\n"; exit; } $swarmConfig = object_merge($defaultSettings, $localSettings); unset($defaultSettingsFile, $localSettingsFile, $defaultSettings, $localSettings); // Validate browserSets // Must be after AutoLoad $swarmUaIndex = BrowserInfo::getSwarmUAIndex(); foreach ($swarmConfig->browserSets as $set => $browsers) { foreach ($browsers as $browser) { if (!isset($swarmUaIndex->{$browser})) { echo "<b>TestSwarm Fatal</b>: Invalid browser ID \"<code>{$browser}</code>\" in browser set \"<code>{$set}</code>\" !\n"; exit; } } } // Timezone date_default_timezone_set($swarmConfig->general->timezone); // Auto-populate web.server