aboutsummaryrefslogtreecommitdiffstats
path: root/storage-backend/lib/functions.common.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'storage-backend/lib/functions.common.inc.php')
-rw-r--r--storage-backend/lib/functions.common.inc.php48
1 files changed, 47 insertions, 1 deletions
diff --git a/storage-backend/lib/functions.common.inc.php b/storage-backend/lib/functions.common.inc.php
index b47268e..d00b555 100644
--- a/storage-backend/lib/functions.common.inc.php
+++ b/storage-backend/lib/functions.common.inc.php
@@ -15,4 +15,50 @@ function generate_uuid() {
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
-?> \ No newline at end of file
+
+function getFromArray($key, $array) {
+ if (array_key_exists($key, $array)
+ && isset($array[$key])
+ && !empty($array[$key])) {
+ return $array[$key];
+ } else {
+ return NULL;
+ }
+}
+
+function format_size($size, $precision = 2) {
+ $sizes = ['bytes', 'Kb', 'Mb', 'Gb', 'Tb'];
+ $i = 0;
+ while (1023 < $size && $i < count($sizes) - 1) {
+ $size /= 1023;
+ ++$i;
+ }
+
+ return number_format($size, $precision).' '.$sizes[$i];
+}
+
+function startsWith($haystack, $needle) {
+ $length = strlen($needle);
+ return (substr($haystack, 0, $length) === $needle);
+}
+
+function endsWith($haystack, $needle) {
+ $length = strlen($needle);
+
+ return $length === 0 || (substr($haystack, -$length) === $needle);
+}
+
+function generatePath($parts, $basePath = __DIR__) {
+ $path = $basePath;
+ if (!is_array($parts)) {
+ $parts = [$parts];
+ }
+ foreach ($parts as $part) {
+ $path .= DIRECTORY_SEPARATOR.generatePathName($part);
+ }
+ return $path;
+}
+
+function generatePathName($name) {
+ return urlencode($name);
+} \ No newline at end of file