Skip to content

Commit e04401b

Browse files
author
Fredrick Peter
committed
upgrade
1 parent 4bd9508 commit e04401b

File tree

8 files changed

+127
-106
lines changed

8 files changed

+127
-106
lines changed

Asset.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class Asset{
1616
* @param string $asset
1717
* - asset file e.g (style.css | js/main.js)
1818
*
19-
* @param bool $cache
19+
* @param bool|null $cache
2020
*
2121
* @return string
2222
*/
23-
static public function asset(?string $asset = null, ?bool $cache = false)
23+
static public function asset(?string $asset = null, $cache = null)
2424
{
2525
// if coniguration has not been used in the global space
2626
// then we call to define paths for us
@@ -31,6 +31,12 @@ static public function asset(?string $asset = null, ?bool $cache = false)
3131
// asset path
3232
$assetPath = ASSET_BASE_DIRECTORY;
3333

34+
// if asset method cache is not null
35+
// then we override the global configuration
36+
if(!is_bool($cache)){
37+
$cache = $assetPath['cache'];
38+
}
39+
3440
// trim
3541
$asset = trim((string) $asset, '/');
3642

@@ -43,7 +49,7 @@ static public function asset(?string $asset = null, ?bool $cache = false)
4349
$cacheTimeAppend = null;
4450

4551
// cache allow from self method
46-
if($cache && $assetPath['cache']){
52+
if($cache){
4753
$cacheTimeAppend = self::getFiletime($file_server) ?? null;
4854
}
4955

@@ -65,7 +71,7 @@ static public function asset(?string $asset = null, ?bool $cache = false)
6571
*
6672
* @return void
6773
*/
68-
static public function config(?string $base_path = null, ?bool $cache = true)
74+
static public function config(?string $base_path = null, ?bool $cache = false)
6975
{
7076
// severs
7177
$server = self::getServers();

Tame.php

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ static public function HeadersSent()
149149
* include if file exist
150150
*
151151
* @param string $path
152-
* - [do not include base path]
152+
* - [base path will be automatically added]
153153
*
154154
* @return void
155155
*/
156156
static public function include($path)
157157
{
158-
$fullPath = trim(self::getBasePath($path), '\/');
158+
$fullPath = self::getBasePath($path);
159159

160160
if(self::exists($fullPath)){
161161
include $fullPath;
@@ -166,13 +166,13 @@ static public function include($path)
166166
* include once if file exist
167167
*
168168
* @param string $path
169-
* - [do not include base path]
169+
* - [base path will be automatically added]
170170
*
171171
* @return void
172172
*/
173173
static public function includeOnce($path)
174174
{
175-
$fullPath = trim(self::getBasePath($path), '\/');
175+
$fullPath = self::getBasePath($path);
176176

177177
if(self::exists($fullPath)){
178178
include_once $fullPath;
@@ -183,13 +183,13 @@ static public function includeOnce($path)
183183
* require if file exist
184184
*
185185
* @param string $path
186-
* - [do not include base path]
186+
* - [base path will be automatically added]
187187
*
188188
* @return void
189189
*/
190190
static public function require($path)
191191
{
192-
$fullPath = trim(self::getBasePath($path), '\/');
192+
$fullPath = self::getBasePath($path);
193193

194194
if(self::exists($fullPath)){
195195
require $fullPath;
@@ -200,13 +200,13 @@ static public function require($path)
200200
* require_once if file exist
201201
*
202202
* @param string $path
203-
* - [do not include base path]
203+
* - [base path will be automatically added]
204204
*
205205
* @return void
206206
*/
207207
static public function requireOnce($path)
208208
{
209-
$fullPath = trim(self::getBasePath($path), '\/');
209+
$fullPath = self::getBasePath($path);
210210

211211
if(self::exists($fullPath)){
212212
require_once $fullPath;
@@ -277,7 +277,7 @@ static public function sizeToBytes($size = '1mb')
277277
* Get file modification time
278278
*
279279
* @param string|null $path
280-
* - [do not include base path]
280+
* - [base path will be automatically added]
281281
*
282282
* @return int|bool
283283
*/
@@ -296,7 +296,7 @@ static public function getFiletime($path = null)
296296
* Get file modification time
297297
*
298298
* @param string|null $path
299-
* - [do not include base path]
299+
* - [base path will be automatically added]
300300
*
301301
* @return int|bool
302302
*/
@@ -759,23 +759,38 @@ static public function formatNumberToNearestThousand(float|int $number = 0)
759759

760760
return $number;
761761
}
762+
763+
/**
764+
* File exist and not a directory
765+
*
766+
* @param string|null $path
767+
* - [full path to file]
768+
*
769+
* @return bool
770+
*/
771+
static public function exists($path = null)
772+
{
773+
return !is_dir($path) && file_exists($path);
774+
}
762775

763776
/**
764777
* Unlink File from Server
765778
*
766-
* @param string $fileToUnlink
767-
* - [full path to file]
779+
* @param string $pathToFile
780+
* - [base path will be automatically added]
768781
*
769-
* @param string|null $checkFile
782+
* @param string|null $fileName
770783
* - [optional] file name. <avatar.png>
771784
*
772785
* @return void
773786
*/
774-
static public function unlinkFile(string $fileToUnlink, $fileName = null)
787+
static public function unlink(string $pathToFile, $fileName = null)
775788
{
776-
if(self::exists($fileToUnlink)){
777-
if(basename($fileToUnlink) != basename((string) $fileName)){
778-
@unlink($fileToUnlink);
789+
$fullPath = self::getBasePath($pathToFile);
790+
791+
if(self::exists($fullPath)){
792+
if(basename($fullPath) != basename((string) $fileName)){
793+
@unlink($fullPath);
779794
}
780795
}
781796
}
@@ -784,7 +799,7 @@ static public function unlinkFile(string $fileToUnlink, $fileName = null)
784799
* Convert json data to array|object
785800
*
786801
* @param string $path
787-
* - [full path to file]
802+
* - [base path will be automatically added]
788803
*
789804
* @param bool $format
790805
* - [optional] `true` will convert to an array
@@ -793,8 +808,10 @@ static public function unlinkFile(string $fileToUnlink, $fileName = null)
793808
*/
794809
static public function convertJsonData($path, $format = true)
795810
{
796-
if(self::exists($path)){
797-
return json_decode(file_get_contents($path), $format);
811+
$fullPath = self::getBasePath($path);
812+
813+
if(self::exists($fullPath)){
814+
return json_decode(file_get_contents($fullPath), $format);
798815
}
799816
}
800817

@@ -859,32 +876,36 @@ static public function saveFileFromURL($url = null, $destination)
859876
* Read PDF TO Browser
860877
*
861878
* @param string|null $path
862-
* - [full path to file]
879+
* - [base path will be automatically added]
863880
*
864881
* @return void
865882
*/
866883
static public function readPDFToBrowser($path = null)
867884
{
868-
if(!empty($path) && self::exists($path)){
885+
$fullPath = self::getBasePath($path);
886+
887+
if(self::exists($fullPath)){
869888
@header("Content-type: application/pdf");
870-
@header("Content-Length: " . filesize($path));
871-
readfile($path);
889+
@header("Content-Length: " . filesize($fullPath));
890+
readfile($fullPath);
872891
}
873892
}
874893

875894
/**
876895
* Convert image to base64
877896
*
878897
* @param string|null $path
879-
* - [full path to file]
898+
* - [base path will be automatically added]
880899
*
881900
* @return null|string
882901
*/
883902
static public function imageToBase64($path = null)
884903
{
885-
if(!empty($path) && self::exists($path)){
886-
$type = pathinfo($path, PATHINFO_EXTENSION);
887-
$data = file_get_contents($path);
904+
$fullPath = self::getBasePath($path);
905+
906+
if(self::exists($fullPath)){
907+
$type = pathinfo($fullPath, PATHINFO_EXTENSION);
908+
$data = file_get_contents($fullPath);
888909

889910
return 'data:image/' . $type . ';base64,' . base64_encode($data);
890911
}
@@ -1169,19 +1190,6 @@ static public function paymentIcon($payment = null)
11691190
return $dataSet[$payment] ?? $dataSet['cc'];
11701191
}
11711192

1172-
/**
1173-
* File exist and not a directory
1174-
*
1175-
* @param string|null $path
1176-
* - [full path to file]
1177-
*
1178-
* @return bool
1179-
*/
1180-
static public function exists($path = null)
1181-
{
1182-
return !is_dir($path) && file_exists($path);
1183-
}
1184-
11851193
/**
11861194
* Replace and recreate path to
11871195
* - (/) slash
@@ -1192,7 +1200,11 @@ static public function exists($path = null)
11921200
*/
11931201
static public function stringReplacer($path = null)
11941202
{
1195-
return Server::cleanServerPath($path);
1203+
return str_replace(
1204+
['\\', '/'],
1205+
DIRECTORY_SEPARATOR,
1206+
trim((string) $path)
1207+
);
11961208
}
11971209

11981210
}

Tests/test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
// Env::loadOrFail();
1414

1515

16-
// PDF()->create([
16+
// TamePDF()->create([
1717
// 'content' => "<h1>Title First</h1> <br> Hello There i Love You!",
1818
// 'destination' => base_path('save.pdf'),
1919
// 'output' => 'download'
2020
// ]);
2121

22-
// Tame::unlinkFile(base_path('welcome.png'), 'default.png')
22+
// Tame::unlink('welcome.png', 'default.png')
2323

2424
// Tame::platformIcon('windows')
2525

Tests/url.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
// URL Helpers
99

1010

11+
config_asset('/', true);
12+
13+
1114
dd(
1215
domain(),
1316

1417
domain('admin'),
1518

16-
asset('js/app.js'),
19+
asset('zip.php'),
1720
);
1821

Tests/zip.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Tamedevelopers\Support\Zip;
4+
5+
require_once __DIR__ . '/../vendor/autoload.php';
6+
7+
// Powerful Zip Class
8+
9+
10+
// Zip::zip('tests', 'newData.zip');
11+
12+
// TameZip()->zip('tests', 'newData.zip');
13+
// TameZip()->unzip('newData.zip', '/');
14+
15+
dd(
16+
17+
base_path('hello.php'),
18+
);
19+

Traits/TameTrait.php

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -173,51 +173,7 @@ static private function openSSLEncrypt()
173173
*/
174174
static private function getBasePath($path = null)
175175
{
176-
return self::stringReplacer(base_path($path));
177-
}
178-
179-
/**
180-
* getPublicPath
181-
*
182-
* @param string|null $path
183-
* @return mixed
184-
*/
185-
static private function getPublicPath($path = null)
186-
{
187-
return self::stringReplacer(base_path($path));
188-
}
189-
190-
/**
191-
* getStoragePath
192-
*
193-
* @param string|null $path
194-
* @return mixed
195-
*/
196-
static private function getStoragePath($path = null)
197-
{
198-
return self::stringReplacer(base_path($path));
199-
}
200-
201-
/**
202-
* getAppPath
203-
*
204-
* @param string|null $path
205-
* @return mixed
206-
*/
207-
static private function getAppPath($path = null)
208-
{
209-
return self::stringReplacer(base_path($path));
210-
}
211-
212-
/**
213-
* getSvgPath
214-
*
215-
* @param string|null $path
216-
* @return mixed
217-
*/
218-
static private function getSvgPath($path = null)
219-
{
220-
return self::stringReplacer(base_path($path));
176+
return base_path($path);
221177
}
222178

223179
}

0 commit comments

Comments
 (0)