Skip to content

Commit 3c0fd29

Browse files
author
Fredrick Peter
committed
version update
1 parent 20959bc commit 3c0fd29

File tree

13 files changed

+165
-91
lines changed

13 files changed

+165
-91
lines changed

Asset.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Asset{
2020
*
2121
* @return string
2222
*/
23-
static public function asset(?string $asset = null, ?bool $cache = true)
23+
static public function asset(?string $asset = null, ?bool $cache = false)
2424
{
2525
// if coniguration has not been used in the global space
2626
// then we call to define paths for us
@@ -70,21 +70,27 @@ static public function config(?string $base_path = null, ?bool $cache = true)
7070
// severs
7171
$server = self::getServers();
7272

73-
// set default
73+
// set default directory
7474
if(empty($base_path)){
75-
$base_path = "assets";
75+
$base_path = "public";
7676
}
7777

7878
// if not defined
7979
if(!defined('ASSET_BASE_DIRECTORY')){
8080
// - Trim forward slash from left and right
8181
$base_path = trim($base_path, '/');
82+
83+
// old url getter helper
84+
$urlFromServer = self::cleanServerPath("{$server['domain']}{$base_path}");
85+
86+
// url helper class
87+
$urlFromhelper = UrlHelper::url();
8288

8389
define('ASSET_BASE_DIRECTORY', [
8490
'cache' => $cache,
8591
'server' => self::formatWithBaseDirectory($base_path),
8692
'domain' => rtrim(
87-
self::cleanServerPath("{$server['domain']}{$base_path}"),
93+
self::cleanServerPath("{$urlFromhelper}{$base_path}"),
8894
'/'
8995
),
9096
]);

Capsule/Manager.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Tamedevelopers\Support\Env;
88
use Tamedevelopers\Support\Str;
9+
use Tamedevelopers\Support\Tame;
910

1011
class Manager{
1112

@@ -149,16 +150,16 @@ static public function isEnvSet($key)
149150
* Set headers with response code
150151
*
151152
* @param mixed $status
152-
* @param callable $function
153+
* @param Closure|null $closure
153154
* @return void
154155
*/
155-
static public function setHeaders($status = 404, callable $function = null)
156+
static public function setHeaders($status = 404, $closure = null)
156157
{
157158
// Set HTTP response status code to 404
158159
@http_response_code($status);
159160

160-
if(is_callable($function)){
161-
$function();
161+
if(Tame::isClosure($closure)){
162+
$closure();
162163
}
163164

164165
// Exit with response 404

Laravel.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,35 @@ static public function svgDirective()
2626

2727
// Register a Blade directive
2828
Blade::directive('svg', function ($expression) {
29-
// Parse the expression to get the path and classes
30-
list($path, $classes) = explode(',', $expression, 2);
3129

32-
// path
33-
34-
// Load the SVG file contents
35-
$svgContent = file_get_contents(public_path(trim($path, '"')));
36-
37-
// Add classes to SVG
38-
$svg = simplexml_load_string($svgContent);
39-
if (!empty($classes)) {
40-
$svg->addAttribute('class', trim($classes, '"'));
41-
}
42-
43-
// Return the modified SVG
44-
return $svg->asXML();
30+
list($path, $class) = array_pad(explode(',', $expression, 2), 2, '');
31+
32+
$path = str_replace(['"', "'"], '', $path);
33+
$class = str_replace(['"', "'"], '', $class);
34+
35+
// fullpath
36+
$fullPath = public_path($path);
37+
38+
// if file exists
39+
if(Tame::exists($fullPath)){
40+
// Load the SVG file contents
41+
$svgContent = file_get_contents($fullPath);
42+
43+
// Parse the SVG content into a SimpleXMLElement
44+
$svg = simplexml_load_string($svgContent);
45+
46+
// If a class is provided, add it to the SVG element
47+
if (!empty($class)) {
48+
if (isset($svg['class'])) {
49+
$svg['class'] .= ' ' . $class;
50+
} else {
51+
$svg->addAttribute('class', $class);
52+
}
53+
}
54+
55+
// Return the modified SVG
56+
return $svg->asXML();
57+
};
4558
});
4659
});
4760
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ composer require tamedevelopers/support
3737

3838
## Asset
3939
- Takes a param as `string` path to asset file
40-
- Default [dir] is set to `assets`
40+
- Default [dir] is set to `public`
4141

4242
```
4343
use Tamedevelopers\Support\Asset;
@@ -175,15 +175,15 @@ Server::config('tests.lang.email', [], 'Tests');
175175
* @param mixed $key
176176
* @return mixed
177177
*/
178-
function __($key){
178+
function __lang($key){
179179
180180
// since the config only takes the filename follow by dot(.) and keyname
181181
// then we can manually include additional folder-name followed by / to indicate that it's a folder
182182
// then message.key_name
183183
// To make this Laravel kind of language, we can add the default value to be returned as the key
184184
// Do not forget that it starts from your root base directory, as the Package already has your root path
185185
186-
return config("en/message.{$key}", "message.{$key}", 'Lang');
186+
return config("en/message.{$key}", "message.{$key}", 'lang');
187187
}
188188
189189

Tame.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @see \Tamedevelopers\Support\Server
1414
* @see \Tamedevelopers\Support\Time
1515
*/
16-
class Tame{
16+
class Tame {
1717

1818
use TameTrait;
1919

@@ -64,14 +64,14 @@ static public function echoJson(int $response = 0, $message = null)
6464
* Check if Class Exists
6565
*
6666
* @param string $class
67-
* @param callable|null $function
68-
* @return mixed
67+
* @param Closure|null $closure
68+
* @return void
6969
*/
70-
static public function class_exists($class, callable $function = null)
70+
static public function class_exists($class, $closure = null)
7171
{
7272
if(class_exists($class)){
73-
if(is_callable($function)){
74-
$function();
73+
if(self::isClosure($closure)){
74+
$closure();
7575
}
7676
}
7777
}
@@ -746,9 +746,6 @@ static public function formatNumberToNearestThousand(float|int $number = 0)
746746
*/
747747
static public function unlinkFile(string $fileToUnlink, $checkFile = null)
748748
{
749-
$fileToUnlink = self::getBasePath($fileToUnlink);
750-
$checkFile = self::getBasePath($checkFile);
751-
752749
if(self::exists($fileToUnlink)){
753750
if(basename($fileToUnlink) != basename($checkFile)){
754751
@unlink($fileToUnlink);
@@ -836,20 +833,18 @@ static public function saveFileFromURL($url = null, $destination = null)
836833
static public function readPDFToBrowser($path = null)
837834
{
838835
if(!empty($path) && self::exists($path)){
839-
// Header content type
840-
header("Content-type: application/pdf");
841-
842-
header("Content-Length: " . filesize($path));
843-
844-
// Send the file to the browser.
836+
@header("Content-type: application/pdf");
837+
@header("Content-Length: " . filesize($path));
845838
readfile($path);
846839
}
847840
}
848841

849842
/**
850843
* Convert image to base64
851844
*
852-
* @param string|null $path_to_image
845+
* @param string|null $path
846+
*
847+
*
853848
* @return null|string
854849
*/
855850
static public function imageToBase64($path = null)

Tests/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// 'output' => 'download'
2020
// ]);
2121

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

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

Tests/translate.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
/**
99
* Custom Language Handler
1010
*
11-
* @param string $key
11+
* @param string $key
12+
* @param string|null $locale
13+
*
1214
* @return mixed
1315
*/
14-
function __lang($key){
16+
function __lang($key, $locale = null){
1517
return Translator::trans(
16-
"message.{$key}",
17-
Translator::getLocale()
18+
"message.{$key}", $locale
1819
);
1920
}
2021

@@ -35,14 +36,15 @@ function configuration($key, $default = null){
3536
return config("configuration/{$key}", $default, 'tests');
3637
}
3738

38-
3939
dd(
40+
4041
__('message.name'),
4142

43+
__('error.forgot'),
4244

4345
__('message.forgot_password'),
4446

45-
__lang('confirm_password'),
47+
__lang('confirm_password', 'cn'),
4648

4749
// configuration('banners'),
4850

Tests/url.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// URL Helpers
99

1010

11-
1211
dd(
1312
domain(),
1413

0 commit comments

Comments
 (0)