initial commit
This commit is contained in:
25
helpers/constants/cache_ttl.php
Normal file
25
helpers/constants/cache_ttl.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache TTL (Time-To-Live)
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is a collection of intervals in seconds that are commong to use
|
||||
| when caching, but written as a more human-friendly phrase.
|
||||
|
|
||||
*/
|
||||
|
||||
define('CACHE_TTL_FIVE_MINUTES', 300);
|
||||
define('CACHE_TTL_FIFTEEN_MINUTES', 900);
|
||||
|
||||
define('CACHE_TTL_HALF_HOUR', 1800);
|
||||
define('CACHE_TTL_ONE_HOUR', 3600);
|
||||
define('CACHE_TTL_TWO_HOURS', 7200);
|
||||
define('CACHE_TTL_THREE_HOURS', 10800);
|
||||
define('CACHE_TTL_SIX_HOURS', 21600);
|
||||
define('CACHE_TTL_TWELVE_HOURS', 43200);
|
||||
|
||||
define('CACHE_TTL_ONE_DAY', 86400);
|
||||
|
||||
define('CACHE_TTL_ONE_WEEK', 604800);
|
73
helpers/constants/http_status_codes.php
Normal file
73
helpers/constants/http_status_codes.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Status Codes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is a collection of HTTP status codes and a corresponding string
|
||||
| that is human-friendly and easy to remember.
|
||||
|
|
||||
*/
|
||||
|
||||
$httpCodes = [
|
||||
// 100's (informational / "hold on")
|
||||
100 => 'HTTP_CONTINUE',
|
||||
101 => 'HTTP_SWITCHING_PROTOCOLS',
|
||||
102 => 'HTTP_PROCESSING',
|
||||
103 => 'HTTP_EARLY_HINTS',
|
||||
|
||||
// 200's (successful / "here you go")
|
||||
200 => 'HTTP_SUCCESS',
|
||||
201 => 'HTTP_CREATED',
|
||||
202 => 'HTTP_ACCEPTED',
|
||||
204 => 'HTTP_NO_CONTENT',
|
||||
205 => 'HTTP_RESET_CONTENT',
|
||||
206 => 'HTTP_PARTIAL_CONTENT',
|
||||
|
||||
// 300's (redirections / "go away")
|
||||
300 => 'HTTP_MULTIPLE_CHOICE',
|
||||
301 => 'HTTP_MOVED_PERMANENTLY',
|
||||
302 => 'HTTP_REDIRECT_FOUND',
|
||||
303 => 'HTTP_SEE_OTHER',
|
||||
304 => 'HTTP_NOT_MODIFIED',
|
||||
307 => 'HTTP_TEMPORARY_REDIRECT',
|
||||
308 => 'HTTP_PERMANENT_REDIRECT',
|
||||
|
||||
// 400's (app got the request but couldn't process it successfully, coding error / "user screwed up")
|
||||
400 => 'HTTP_BAD_REQUEST',
|
||||
401 => 'HTTP_UNAUTHORIZED',
|
||||
402 => 'HTTP_PAYMENT_REQUIRED',
|
||||
403 => 'HTTP_FORBIDDEN',
|
||||
404 => 'HTTP_NOT_FOUND',
|
||||
405 => 'HTTP_METHOD_NOT_ALLOWED',
|
||||
406 => 'HTTP_NOT_ACCEPTABLE',
|
||||
408 => 'HTTP_TIMEOUT',
|
||||
409 => 'HTTP_CONFLICT',
|
||||
410 => 'HTTP_GONE',
|
||||
412 => 'HTTP_PRECONDITION_FAILED',
|
||||
413 => 'HTTP_PAYLOAD_TOO_LARGE',
|
||||
415 => 'HTTP_UNSUPPORTED_MEDIA',
|
||||
413 => 'HTTP_TOO_LARGE',
|
||||
417 => 'HTTP_EXPECTATION_FAIL',
|
||||
418 => 'HTTP_TEAPOT',
|
||||
422 => 'HTTP_UNPROCESSABLE_ENTITY',
|
||||
423 => 'HTTP_LOCKED',
|
||||
424 => 'HTTP_FAILED_DEPENDENCY',
|
||||
236 => 'HTTP_UPGRADE_REQUIRED',
|
||||
428 => 'HTTP_PRECONDITION_REQUIRED',
|
||||
429 => 'HTTP_TOO_MANY_REQUESTS',
|
||||
451 => 'HTTP_GAG_ORDER',
|
||||
|
||||
// 500's (server-level problem, process died or configuration is incorrect / "server screwed up")
|
||||
500 => 'HTTP_SERVER_ERROR',
|
||||
501 => 'HTTP_NOT_IMPLEMENTED',
|
||||
503 => 'HTTP_UNAVAILABLE',
|
||||
530 => 'HTTP_SUSPENDED',
|
||||
];
|
||||
|
||||
foreach ($httpCodes as $code => $slug) {
|
||||
if (! defined($slug)) {
|
||||
define($slug, $code);
|
||||
}
|
||||
}
|
289
helpers/global_functions.php
Normal file
289
helpers/global_functions.php
Normal file
@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is a home for functions that don't belong to any one class and
|
||||
| that should be available anywhere in the application.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('snake2Title')) {
|
||||
/**
|
||||
* Convert a snake case string to a title with spaces
|
||||
* and every word capitalized.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $stakeSlug A snake case string, commonly a slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function snake2Title(string $snakeSlug): string
|
||||
{
|
||||
$output = preg_replace('/\_/', ' ', $snakeSlug);
|
||||
return ucwords($output);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('carbon')) {
|
||||
/**
|
||||
* Return a Carbon object based on a given timestring.
|
||||
* It will attempt to find a timezone in the current
|
||||
* session but default to UTC.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string|null $timestring
|
||||
*
|
||||
* @return \Carbon\Carbon
|
||||
*/
|
||||
function carbon(?string $timestring = null): \Carbon\Carbon
|
||||
{
|
||||
$carbon = Carbon\Carbon::now(session('timezone_name'));
|
||||
if (! empty($timestring)) {
|
||||
$carbon = Carbon\Carbon::parse($timestring, session('timezone_name'));
|
||||
}
|
||||
return $carbon;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('jddayofweek')) {
|
||||
/**
|
||||
* Returns the day of the week. Can return a string or an integer depending on the mode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int|null $intDay
|
||||
* @param int $mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function jddayofweek(?int $intDay = null, int $mode = 0): string
|
||||
{
|
||||
if (is_null($intDay)) {
|
||||
$intDay = date('l');
|
||||
}
|
||||
|
||||
if ($mode === 0) {
|
||||
return $intDay;
|
||||
}
|
||||
|
||||
return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][$intDay];
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('is_serialized')) {
|
||||
/**
|
||||
* Check a value to find if it was serialized.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param bool $strict
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_serialized($data, bool $strict = true): bool
|
||||
{
|
||||
// If it isn't a string, it isn't serialized.
|
||||
if (! is_string($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = trim($data);
|
||||
if ('N;' === $data) {
|
||||
return true;
|
||||
}
|
||||
if (strlen($data) < 4) {
|
||||
return false;
|
||||
}
|
||||
if (':' !== $data[1]) {
|
||||
return false;
|
||||
}
|
||||
if ($strict) {
|
||||
$lastc = substr($data, -1);
|
||||
if (';' !== $lastc && '}' !== $lastc) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$semicolon = strpos($data, ';');
|
||||
$brace = strpos($data, '}');
|
||||
// Either ; or } must exist.
|
||||
if (!$semicolon && !$brace) {
|
||||
return false;
|
||||
}
|
||||
// But neither must be in the first X characters.
|
||||
if ($semicolon && $semicolon < 3) {
|
||||
return false;
|
||||
}
|
||||
if ($brace && $brace < 4) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$token = $data[0];
|
||||
switch ($token) {
|
||||
case 's':
|
||||
if ($strict) {
|
||||
if ('"' !== substr($data, -2, 1)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (!strpos($data, '"')) {
|
||||
return false;
|
||||
}
|
||||
// Or else fall through.
|
||||
case 'a':
|
||||
case 'O':
|
||||
return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
|
||||
case 'b':
|
||||
case 'i':
|
||||
case 'd':
|
||||
$end = $strict ? '$' : '';
|
||||
return (bool) preg_match("/^{$token}:[0-9.E+-]+;$end/", $data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('maybe_unserialize')) {
|
||||
/**
|
||||
* Unserialize data only if it was serialized. Will return
|
||||
* an array if it was a serialized string, otherwise it
|
||||
* will return whatever was passed into the function
|
||||
* leaving it untouched.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function maybe_unserialize($data)
|
||||
{
|
||||
if (is_serialized($data)) { // Don't attempt to unserialize data that wasn't serialized going in.
|
||||
return @unserialize(trim($data));
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('cel2Fah')) {
|
||||
/**
|
||||
* Convert from celsius to fahrenheit.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $celsius
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function cel2Fah($celsius, int $preceision = 0): float
|
||||
{
|
||||
return round((($celsius * (9/5)) + 32), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('fah2Cel')) {
|
||||
/**
|
||||
* Convert from fahrenheit to celsius.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $fahrenheit
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function fah2Cel($fahrenheit, int $preceision = 1): float
|
||||
{
|
||||
return round(($fahrenheit - 32 * (5/9)), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('meters2Miles')) {
|
||||
/**
|
||||
* Convert from meters to miles.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $meters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function meters2Miles($meters, int $preceision = 1): float
|
||||
{
|
||||
return round(($meters * 0.00062137), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('kilometers2Miles')) {
|
||||
/**
|
||||
* Convert from kilometers to meters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $kilometers
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function kilometers2Miles($kilometers, int $preceision = 1): float
|
||||
{
|
||||
return round(($kilometers * 1.609), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('m2Km')) {
|
||||
/**
|
||||
* Convert from meters to kilometers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $meters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function m2Km($meters, int $preceision = 1): float
|
||||
{
|
||||
return round(($meters / 1000), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('mm2Inches')) {
|
||||
/**
|
||||
* Convert from milimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $milimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function mm2Inches($milimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($milimeters / 25.4), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('pa2Mbar')) {
|
||||
/**
|
||||
* Convert from pascals to milibars.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $pascals
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function pa2Mbar($pascals, int $preceision = 1): float
|
||||
{
|
||||
return round(($pascals / 100), $preceision);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user