2019-09-09 23:48:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function ensure($bool, $error_msg = "")
|
|
|
|
{
|
|
|
|
if (!$bool)
|
|
|
|
throw new AssertionError($error_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatDate($date = NULL, $with_time = false)
|
|
|
|
{
|
|
|
|
if ($date == NULL)
|
|
|
|
$date = date("yyyy-mm-dd");
|
|
|
|
|
|
|
|
return strftime("%d %B %G" . ($with_time ? " %H:%M" : ""), strtotime($date));
|
|
|
|
}
|
|
|
|
|
|
|
|
function dateWellFormed($date, $with_time = false)
|
|
|
|
{
|
|
|
|
return date_parse_from_format($with_time ? "yyyy-mm-dd HH-MM:ss" : "yy-mm-dd", $date) !== false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function genRandomPhrase($size, $uppercase = false)
|
|
|
|
{
|
|
|
|
$alphabet = $uppercase ? "0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" : "0123456789abcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
|
|
|
|
$phrase = "";
|
|
|
|
for ($i = 0; $i < $size; ++$i) {
|
|
|
|
$phrase .= $alphabet[rand(0, strlen($alphabet) - 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $phrase;
|
2019-09-21 18:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getExtFromMimeType($mime_type)
|
|
|
|
{
|
|
|
|
switch ($mime_type) {
|
|
|
|
case "application/pdf":
|
|
|
|
return ".pdf";
|
|
|
|
case "image/png":
|
|
|
|
return ".png";
|
|
|
|
case "image/jpg":
|
|
|
|
case "image/jpeg":
|
|
|
|
return ".jpg";
|
|
|
|
case "application/zip":
|
|
|
|
return ".zip";
|
|
|
|
}
|
|
|
|
return "";
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|