This repository has been archived on 2026-05-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
osu-optimizer-php/libraries/utils.php
T
2021-06-17 22:03:32 +02:00

52 lines
1008 B
PHP

<?php
class utils
{
public static function globsafe(string $path) : string
{
$path = str_replace('[', '\[', $path);
$path = str_replace(']', '\]', $path);
$path = str_replace('\[', '[[]', $path);
$path = str_replace('\]', '[]]', $path);
return $path;
}
public static function recursive_zip_map($zip, $root, $path)
{
$files = glob($path . "/*");
foreach ($files as $file)
{
if (is_dir($file))
{
self::recursive_zip_map($zip, $root, $file);
}
else
{
$relative = str_replace(array("@-".$root."/", "@-".$root), "", "@-".$file);
$zip->addFile($file, $relative);
}
}
}
// does nothing if the directory already exists
public static function make_directory(string $directory) : void
{
if (!file_exists($directory))
{
mkdir($directory, 0777, true);
}
}
public static function load_json(string $path) : array
{
try
{
$raw = file_get_contents($path);
}
catch
{
$raw = "";
}
return json_decode($raw, true) ?? array();
}
}