Skip to content

Commit 9a53aae

Browse files
author
Fredrick Peter
committed
update
1 parent d7c6b64 commit 9a53aae

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed

Asset.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ class Asset{
1616
* @param string $asset
1717
* - asset file e.g (style.css | js/main.js)
1818
*
19-
* @param string $assetDir
20-
* - Default is `assets` folder
19+
* @param bool $cache
2120
*
2221
* @return string
2322
*/
24-
static public function asset(?string $asset = null)
23+
static public function asset(?string $asset = null, ?bool $cache = true)
2524
{
2625
// if coniguration has not been used in the global space
2726
// then we call to define paths for us
@@ -40,10 +39,15 @@ static public function asset(?string $asset = null)
4039
// file server path
4140
$file_server = "{$assetPath['server']}/{$asset}";
4241

43-
// cache
44-
$cache = $assetPath['cache'] ? self::getFiletime($file_server) : null;
42+
// append file update time
43+
$cacheTimeAppend = null;
4544

46-
return "{$file_domain}{$cache}";
45+
// cache allow from self method
46+
if($cache && $assetPath['cache']){
47+
$cacheTimeAppend = self::getFiletime($file_server) ?? null;
48+
}
49+
50+
return "{$file_domain}{$cacheTimeAppend}";
4751
}
4852

4953
/**
@@ -53,7 +57,7 @@ static public function asset(?string $asset = null)
5357
* - [optional] Default is `base_directory/assets`
5458
* - If set and directory is not found, then we revert back to the default
5559
*
56-
* @param string $cache
60+
* @param bool $cache
5761
* - [optional] Default is true
5862
* - End point of link `?v=xxxxxxxx` is with cache of file time change
5963
* - This will automatically tells the broswer to fetch new file if the time change

Tame.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ static public function sizeToBytes($size = '1mb')
249249
*
250250
* @param string|null $path
251251
*
252-
* @return mixed
253-
* - int|bool
252+
* @return int|bool
254253
*/
255254
static public function getFiletime($path = null)
256255
{
@@ -263,6 +262,18 @@ static public function getFiletime($path = null)
263262
return false;
264263
}
265264

265+
/**
266+
* Get file modification time
267+
*
268+
* @param string|null $path
269+
*
270+
* @return int|bool
271+
*/
272+
static public function fileTime($path = null)
273+
{
274+
return self::getFiletime($path);
275+
}
276+
266277
/**
267278
* Count the numbers between $index and $amount (inclusive) that are divisible by $index.
268279
*
@@ -671,6 +682,19 @@ static public function html($string = null)
671682
return html_entity_decode((string) $string, ENT_HTML5, 'UTF-8');
672683
}
673684

685+
/**
686+
* Convert string to clean text without html tags
687+
*
688+
* @param string|null $string
689+
*
690+
* @return string
691+
* - strip all tags from string content
692+
*/
693+
static public function text($string = null)
694+
{
695+
return strip_tags((string) $string);
696+
}
697+
674698
/**
675699
* Filter sanitize string
676700
*

helpers.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,20 @@ function env_update(?string $key = null, string|bool $value = null, ?bool $quote
227227
}
228228
}
229229

230-
if (! AppIsNotCorePHP() && ! function_exists('asset')) {
230+
if (! function_exists('asset')) {
231231
/**
232232
* Create assets Real path url
233233
*
234234
* @param string $asset
235235
* - asset file e.g (style.css | js/main.js)
236236
*
237+
* @param bool $cache
238+
*
237239
* @return string
238240
*/
239-
function asset($asset = null)
241+
function asset($asset = null, ?bool $cache = false)
240242
{
241-
return Asset::asset($asset);
243+
return Asset::asset($asset, $cache);
242244
}
243245
}
244246

@@ -251,19 +253,41 @@ function asset($asset = null)
251253
* - If set and directory is not found, then we revert back to the default
252254
*
253255
* @param string $cache
254-
* - [optional] Default is true
256+
* - [optional] Default is false
255257
* - End point of link `?v=xxxxxxxx` is with cache of file time change
256258
* - This will automatically tells the broswer to fetch new file if the time change
257259
* - Time will only change if you make changes or modify the request file
258260
*
259261
* @return void
260262
*/
261-
function asset_config($base_path = null, ?bool $cache = true)
263+
function asset_config($base_path = null, ?bool $cache = false)
262264
{
263265
Asset::config($base_path, $cache);
264266
}
265267
}
266268

269+
if (! function_exists('config_asset')) {
270+
/**
271+
* Configure Assets Default Directory
272+
*
273+
* @param string $base_path
274+
* - [optional] Default is `base_directory/assets`
275+
* - If set and directory is not found, then we revert back to the default
276+
*
277+
* @param string $cache
278+
* - [optional] Default is true
279+
* - End point of link `?v=xxxxxxxx` is with cache of file time change
280+
* - This will automatically tells the broswer to fetch new file if the time change
281+
* - Time will only change if you make changes or modify the request file
282+
*
283+
* @return void
284+
*/
285+
function config_asset($base_path = null, ?bool $cache = true)
286+
{
287+
asset_config($base_path, $cache);
288+
}
289+
}
290+
267291
if (! AppIsNotCorePHP() && ! function_exists('__')) {
268292
/**
269293
* Translate the given message.

0 commit comments

Comments
 (0)