Skip to content

Commit 6fe6239

Browse files
committed
🔧 improve on public_path() and writable_path() functions
Signed-off-by: otengkwame <[email protected]>
1 parent 0330970 commit 6fe6239

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Core/helpers/asset_helper.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@
99
* Path to the public directory
1010
*
1111
* @param string $path
12+
* @param string $resource
1213
* @return string
1314
*/
14-
function public_path($path = '')
15+
function public_path($path = '', $resource = '')
1516
{
17+
if ( ! empty($path) && !empty($resource)) {
18+
return FCPATH . $path . DIRECTORY_SEPARATOR . $resource;
19+
}
20+
1621
if ( ! empty($path) && is_dir(FCPATH . $path)) {
1722
return FCPATH . $path . DIRECTORY_SEPARATOR;
1823
}
1924

25+
if ( ! empty($path) && is_file(FCPATH . $path)) {
26+
return FCPATH . $path;
27+
}
28+
2029
if (empty($path)) {
2130
return FCPATH;
2231
}
@@ -64,14 +73,24 @@ function app_path($path = '')
6473
* Path to the writable directory
6574
*
6675
* @param string $path
76+
* @param string $resource
6777
* @return string
6878
*/
69-
function writable_path($path = '')
79+
function writable_path($path = '', $resource = '')
7080
{
81+
82+
if ( ! empty($path) && !empty($resource)) {
83+
return WRITABLEPATH . $path . DIRECTORY_SEPARATOR . $resource;
84+
}
85+
7186
if ( ! empty($path) && is_dir(WRITABLEPATH . $path)) {
7287
return WRITABLEPATH . $path . DIRECTORY_SEPARATOR;
7388
}
7489

90+
if ( ! empty($path) && is_file(WRITABLEPATH . $path)) {
91+
return WRITABLEPATH . $path;
92+
}
93+
7594
return;
7695
}
7796
}
@@ -107,7 +126,7 @@ function resource($path = null, $item = null)
107126
}
108127

109128
if ( ! is_null($item)) {
110-
$path .= '/'.$item;
129+
$path .= DIRECTORY_SEPARATOR .$item;
111130
}
112131

113132
return (!empty($path)) ? load_path($path) : site_url() . ASSETS;

0 commit comments

Comments
 (0)