first commit

This commit is contained in:
ct
2025-05-28 12:59:01 +08:00
commit 21526508b1
230 changed files with 60411 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
if (! function_exists('array_to_object_2025')) {
/**
* A magic function that turns all nested array into nested objects. Calling it with no parameter would result in a empty object.
*
* @param mixed $array The array to be recursively casted into an object.
* @return \stdClass|null Returns null if the given parameter is not either an array or an object.
*/
function array_to_object_2025($array = []): ?stdClass
{
if (is_object($array)) {
return $array;
}
if (! is_array($array)) {
return null;
}
$object = new \stdClass;
if (! isset($array) || empty($array)) {
return $object;
}
foreach ($array as $k => $v) {
if (mb_strlen($k)) {
if (is_array($v)) {
if (array_is_assoc($v)) {
// Convert associative arrays to objects
$object->{$k} = array_to_object_2025($v);
} else {
// For indexed arrays, keep them as arrays but process their elements
$object->{$k} = [];
foreach ($v as $idx => $item) {
if (is_array($item)) {
$object->{$k}[$idx] = array_to_object_2025($item);
} else {
$object->{$k}[$idx] = $item;
}
}
}
} else {
$object->{$k} = $v;
}
}
}
return $object;
}
}
if (! function_exists('array_is_assoc')) {
/**
* Determines whether or not an array is an associative array.
*
* @param array $array The array to be evaluated.
*/
function array_is_assoc($array): bool
{
if (! is_array($array)) {
return false;
}
if ($array === []) {
return false;
}
return array_keys($array) !== range(0, count($array) - 1);
}
}

View File

@@ -0,0 +1,37 @@
<?php
if (! function_exists('is_empty')) {
/**
* A better function to check if a value is empty or null. Strings, arrays, and Objects are supported.
*
* @param mixed $value
*/
function is_empty($value): bool
{
if (is_null($value)) {
return true;
}
if (is_string($value)) {
if ($value === '') {
return true;
}
}
if (is_array($value)) {
if (count($value) === 0) {
return true;
}
}
if (is_object($value)) {
$value = (array) $value;
if (count($value) === 0) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,8 @@
<?php
if (! function_exists('epoch_now_timestamp')) {
function epoch_now_timestamp($multiplier = 1000)
{
return (int) round(microtime(true) * $multiplier);
}
}

View File

@@ -0,0 +1,6 @@
<?php
include 'comparision_helpers.php';
include 'cast_helpers.php';
include 'generation_helpers.php';
include 'user_access_helpers.php';

View File

@@ -0,0 +1,58 @@
<?php
use App\Models\User;
if (! function_exists('user_is_master_admin')) {
function user_is_master_admin(User $user)
{
$emails = ['autopilotshorts@gmail.com', 'team@autopilotshorts.com', 'charles@exastellar.com'];
$user_id = 1;
if ($user->id == $user_id) {
return true;
} elseif (in_array($user->email, $emails)) {
return true;
}
return false;
}
}
if (! function_exists('user_is_blocked_from_purchase')) {
function user_is_blocked_from_purchase(User $user)
{
$emails = ['productionlittlebird@gmail.com'];
if (in_array($user->email, $emails)) {
return true;
}
return false;
}
}
if (! function_exists('user_can_generate_demo_videos')) {
function user_can_generate_demo_videos(User $user)
{
return user_is_master_admin($user);
}
}
if (! function_exists('user_is_external_reviewer')) {
function user_is_external_reviewer(User $user)
{
$emails = [
'shaebaelish.623259@gmail.com',
];
if (in_array($user->email, $emails)) {
return true;
}
return false;
}
}