Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Clubphp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Clubphp
Commits
7bf7327d
Commit
7bf7327d
authored
Apr 07, 2026
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update 1 files via Son of Anton
parent
ae64a019
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
143 deletions
+16
-143
Helpers.php
app/Core/Helpers.php
+16
-143
No files found.
app/Core/Helpers.php
View file @
7bf7327d
<?php
declare
(
strict_types
=
1
);
use
App\Core\App
;
use
App\Core\Database
;
use
App\Core\Response
;
use
App\Core\CSRF
;
function
env
(
string
$key
,
$default
=
null
)
{
return
$_ENV
[
$key
]
??
$_SERVER
[
$key
]
??
$default
;
}
function
app
()
:
App
{
return
App
::
getInstance
();
}
function
db
()
:
Database
{
return
App
::
getInstance
()
->
db
();
}
function
config
(
string
$key
=
null
,
$default
=
null
)
{
if
(
$key
===
null
)
{
return
App
::
getInstance
()
->
config
();
}
return
App
::
getInstance
()
->
config
(
$key
,
$default
);
}
function
session
(
string
$key
=
null
,
$default
=
null
)
{
$session
=
App
::
getInstance
()
->
session
();
if
(
$key
===
null
)
{
return
$session
;
// Find the url() function and replace it with this:
if
(
!
function_exists
(
'url'
))
{
function
url
(
string
$path
=
''
)
:
string
{
$path
=
ltrim
(
$path
,
'/'
);
// For assets and internal links, use relative path from web root
// This avoids all protocol/host mismatch issues
$basePath
=
rtrim
(
parse_url
(
config
(
'app.url'
,
''
),
PHP_URL_PATH
)
?:
''
,
'/'
);
if
(
$path
===
''
)
{
return
$basePath
?:
'/'
;
}
return
$basePath
.
'/'
.
$path
;
}
return
$session
->
get
(
$key
,
$default
);
}
function
redirect
(
string
$url
)
:
Response
{
return
(
new
Response
())
->
redirect
(
$url
);
}
function
url
(
string
$path
=
''
)
:
string
{
$base
=
rtrim
(
App
::
getInstance
()
->
config
(
'app.url'
,
''
),
'/'
);
return
$base
.
'/'
.
ltrim
(
$path
,
'/'
);
}
function
route
(
string
$name
,
array
$params
=
[])
:
string
{
return
\App\Core\Router
::
url
(
$name
,
$params
);
}
function
old
(
string
$key
,
$default
=
''
)
{
$old
=
App
::
getInstance
()
->
session
()
->
get
(
'_old_input'
,
[]);
return
$old
[
$key
]
??
$default
;
}
function
csrf_field
()
:
string
{
return
CSRF
::
field
();
}
function
e
(
?
string
$value
)
:
string
{
return
htmlspecialchars
(
$value
??
''
,
ENT_QUOTES
,
'UTF-8'
);
}
function
__
(
?
string
$key
,
?
string
$default
=
null
)
:
string
{
return
$key
??
$default
??
''
;
}
function
now
()
:
string
{
return
date
(
'Y-m-d H:i:s'
);
}
function
today
()
:
string
{
return
date
(
'Y-m-d'
);
}
function
money
(
?
string
$amount
)
:
string
{
if
(
$amount
===
null
||
$amount
===
''
)
return
'0.00 ج.م'
;
$formatted
=
number_format
((
float
)
$amount
,
2
,
'.'
,
','
);
return
$formatted
.
' ج.م'
;
}
function
percentage
(
?
string
$value
)
:
string
{
if
(
$value
===
null
)
return
'0%'
;
return
$value
.
'%'
;
}
function
age_from_dob
(
string
$dob
)
:
array
{
try
{
$birth
=
new
\DateTime
(
$dob
);
$now
=
new
\DateTime
();
$diff
=
$now
->
diff
(
$birth
);
return
[
'years'
=>
$diff
->
y
,
'months'
=>
$diff
->
m
];
}
catch
(
\Exception
$e
)
{
return
[
'years'
=>
0
,
'months'
=>
0
];
}
}
function
arabic_date
(
string
$date
)
:
string
{
$months
=
[
1
=>
'يناير'
,
2
=>
'فبراير'
,
3
=>
'مارس'
,
4
=>
'أبريل'
,
5
=>
'مايو'
,
6
=>
'يونيو'
,
7
=>
'يوليو'
,
8
=>
'أغسطس'
,
9
=>
'سبتمبر'
,
10
=>
'أكتوبر'
,
11
=>
'نوفمبر'
,
12
=>
'ديسمبر'
,
];
try
{
$dt
=
new
\DateTime
(
$date
);
return
$dt
->
format
(
'd'
)
.
' '
.
$months
[(
int
)
$dt
->
format
(
'm'
)]
.
' '
.
$dt
->
format
(
'Y'
);
}
catch
(
\Exception
$e
)
{
return
$date
;
}
}
function
is_arabic
(
string
$text
)
:
bool
{
return
(
bool
)
preg_match
(
'/[\p{Arabic}]/u'
,
$text
);
}
function
generate_uuid
()
:
string
{
$data
=
random_bytes
(
16
);
$data
[
6
]
=
chr
(
ord
(
$data
[
6
])
&
0x0f
|
0x40
);
$data
[
8
]
=
chr
(
ord
(
$data
[
8
])
&
0x3f
|
0x80
);
return
vsprintf
(
'%s%s-%s-%s-%s-%s%s%s'
,
str_split
(
bin2hex
(
$data
),
4
));
}
function
mask_national_id
(
string
$nid
)
:
string
{
if
(
strlen
(
$nid
)
!==
14
)
return
$nid
;
return
substr
(
$nid
,
0
,
3
)
.
str_repeat
(
'*'
,
9
)
.
substr
(
$nid
,
12
,
2
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment