aboutsummaryrefslogtreecommitdiffstats
path: root/storage-backend/lib/functions.common.inc.php
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2018-10-17 22:08:12 +0200
committersteckbrief <steckbrief@chefmail.de>2018-10-17 22:08:12 +0200
commitbc439cd988dd308a64d0111f766716d54d3648d5 (patch)
tree335ebb5f1e2db53035e959de1a95b96456e618b4 /storage-backend/lib/functions.common.inc.php
parent840bd494f97effaede00d2bbda3d1503887f1f83 (diff)
adds common and http protocol functionalities
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