initial import
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* Shared configuration for maximum base64 payload sizes.
|
||||
*/
|
||||
|
||||
define('BASE64_CHUNK_CONFIG_FILE', __DIR__ . '/config/base64-chunks.php');
|
||||
|
||||
function base64_chunk_defaults()
|
||||
{
|
||||
return array(
|
||||
'racket_zip_max_base64_kb' => 8192,
|
||||
'package_zip_max_base64_kb' => 2048,
|
||||
);
|
||||
}
|
||||
|
||||
function load_base64_chunk_config()
|
||||
{
|
||||
$defaults = base64_chunk_defaults();
|
||||
$config = is_file(BASE64_CHUNK_CONFIG_FILE)
|
||||
? require BASE64_CHUNK_CONFIG_FILE
|
||||
: array();
|
||||
|
||||
if (!is_array($config)) {
|
||||
$config = array();
|
||||
}
|
||||
|
||||
foreach ($defaults as $key => $default) {
|
||||
$value = (int)($config[$key] ?? $default);
|
||||
$config[$key] = $value > 0 ? $value : $default;
|
||||
}
|
||||
|
||||
return array_intersect_key($config, $defaults);
|
||||
}
|
||||
|
||||
function save_base64_chunk_config($config)
|
||||
{
|
||||
$defaults = base64_chunk_defaults();
|
||||
$clean = array();
|
||||
|
||||
foreach ($defaults as $key => $default) {
|
||||
$value = (int)($config[$key] ?? $default);
|
||||
|
||||
if ($value < 1) {
|
||||
throw new InvalidArgumentException('Base64 chunk size must be at least 1 KiB.');
|
||||
}
|
||||
|
||||
$clean[$key] = $value;
|
||||
}
|
||||
|
||||
$php = "<?php\n" .
|
||||
"/*\n" .
|
||||
" * Maximale grootte van base64-payloads, in KiB.\n" .
|
||||
" *\n" .
|
||||
" * 1 KiB = 1024 bytes. De splitter rondt intern waar nodig naar beneden af\n" .
|
||||
" * zodat de binaire chunks netjes naar base64 omgezet kunnen worden.\n" .
|
||||
" */\n\n" .
|
||||
"return " . var_export($clean, true) . ";\n";
|
||||
|
||||
$tmp = BASE64_CHUNK_CONFIG_FILE . '.tmp';
|
||||
|
||||
if (file_put_contents($tmp, $php, LOCK_EX) === false) {
|
||||
throw new RuntimeException('Could not write temporary base64 chunk config.');
|
||||
}
|
||||
|
||||
if (!rename($tmp, BASE64_CHUNK_CONFIG_FILE)) {
|
||||
@unlink($tmp);
|
||||
throw new RuntimeException('Could not replace base64 chunk config.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user