Skip to content

Commit 4674450

Browse files
author
Fredrick Peter
committed
Laravel Support Class Added
1 parent f6e2f58 commit 4674450

File tree

7 files changed

+146
-88
lines changed

7 files changed

+146
-88
lines changed

Hash.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111

1212
final class Hash {
1313

14-
/**
15-
* Count
16-
* @var string
17-
*/
18-
private const PBKDF2_SALT = "\x2d\xb7\x68\x1a";
19-
20-
2114
/**
2215
* Password Encrypter.
2316
* This function encrypts a password using bcrypt with a generated salt.
@@ -57,20 +50,6 @@ static public function check($newPassword, $oldHashedPassword)
5750
return password_verify($newPassword, $oldHashedPassword);
5851
}
5952

60-
/**
61-
* Hash String
62-
*
63-
* @param string $string
64-
* @param int $length
65-
* @param string $type
66-
* @param int $interation
67-
* @return void
68-
*/
69-
static public function stringHash(?string $string, $length = 100, $type = 'sha256', $interation = 100)
70-
{
71-
return hash_pbkdf2($type, mt_rand() . $string, self::PBKDF2_SALT, $interation, $length);
72-
}
73-
7453
/**
7554
* Throw error if password more than maximum allowed legnth
7655
*

Laravel.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tamedevelopers\Support;
6+
7+
use Tamedevelopers\Support\Tame;
8+
use Illuminate\Support\Facades\Blade;
9+
10+
11+
/**
12+
* Laravel Wrapper
13+
*/
14+
class Laravel{
15+
16+
/**
17+
* Create SVG Directrives
18+
*
19+
* @usage @svg('path_to_svg')
20+
*
21+
* @return mixed
22+
*/
23+
static public function svgDirective()
24+
{
25+
Tame::class_exists('Illuminate\Support\Facades\Blade', function(){
26+
27+
// Register a Blade directive
28+
Blade::directive('svg', function ($expression) {
29+
// Parse the expression to get the path and classes
30+
list($path, $classes) = explode(',', $expression, 2);
31+
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();
45+
});
46+
});
47+
}
48+
49+
}

PDF.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
* Usage: composer require dompdf/dompdf
1818
* @url https://github.com/dompdf/dompdf/blob/v0.8.2/src/Adapter/CPDF.php#L45
1919
* @url https://github.com/dompdf/dompdf
20-
*
21-
* @property object \Dompdf\Dompdf|object
22-
* @property object \Dompdf\Options|object
2320
*/
2421
class PDF{
2522

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Prior to installing `support package` get the [Composer](https://getcomposer.org
3333
**Step 1** — update your `composer.json`:
3434
```composer.json
3535
"require": {
36-
"tamedevelopers/support": "^1.0.0"
36+
"tamedevelopers/support": "^1.0.1"
3737
}
3838
```
3939

@@ -203,19 +203,20 @@ function __($key){
203203
--- Structure of folder example
204204
--- (d) for directory and (f) for file
205205
206-
Base -d ---
207-
Lang -d --
208-
en -d
209-
message.php -f
210-
error.php -f
211-
212-
tr -d
213-
message.php -f
214-
error.php -f
206+
- Base
207+
- Lang
208+
- en
209+
- message.php (File)
210+
- error.php (File)
211+
- tr
212+
- message.php (File)
213+
- error.php (File)
215214
```
216215

217216
- or -- `Helpers Function`
218217
```
218+
server()->config("en/message.{$key}", "message.{$key}", 'Lang');
219+
219220
server()->config("app.name");
220221
```
221222

Server.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
use Tamedevelopers\Support\Traits\ServerTrait;
99
use Tamedevelopers\Support\Traits\ReusableTrait;
1010

11-
final class Server{
11+
class Server{
1212

1313
use ServerTrait, ReusableTrait;
14-
1514

1615
/**
1716
* Get the value of a configuration option.
@@ -186,7 +185,7 @@ private static function isNotValidArray(mixed $data = null)
186185
}
187186

188187
/**
189-
* Check if a string is valid JSON.
188+
* Check if data is valid JSON.
190189
*
191190
* @param mixed $data
192191
* @return bool

Tame.php

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class Tame{
3434
*/
3535
protected const GB = 1024 * self::MB;
3636

37+
/**
38+
* Salter String
39+
* @var string
40+
*/
41+
private const PBKDF2_SALT = "\x2d\xb7\x68\x1a";
42+
3743

3844
/**
3945
* Echo `json_encode` with response and message
@@ -47,6 +53,22 @@ static public function echoJson(int $response = 0, string $message = 'null')
4753
echo json_encode(['response' => $response, 'message' => $message]);
4854
}
4955

56+
/**
57+
* Check if Class Exists
58+
*
59+
* @param string $class
60+
* @param callable $function
61+
* @return mixed
62+
*/
63+
static public function class_exists($class, callable $function)
64+
{
65+
if(class_exists($class)){
66+
if(is_callable($function)){
67+
$function();
68+
}
69+
}
70+
}
71+
5072
/**
5173
* PHP Version Compare
5274
*
@@ -609,10 +631,35 @@ static public function removeSpecialChars(?string $string = null)
609631
return null;
610632
}
611633

612-
// Remove anything that's not a letter, number, or whitespace
613-
$clean = preg_replace('/[^\p{L}\p{N}\s]/u', '', $string);
634+
return self::cleanTagsForURL($string);
635+
}
636+
637+
/**
638+
* Clean tags for use in URLs, considering multiple language modules.
639+
*
640+
* @param string|null $string The input string to clean.
641+
* @return string The cleaned string.
642+
*/
643+
static public function cleanTagsForURL(?string $string = null)
644+
{
645+
// Remove unwanted characters from the string
646+
$string = preg_replace('/[^\p{L}\p{N}\s]/u', '', (string) $string);
647+
648+
return trim($string);
649+
}
614650

615-
return $clean;
651+
/**
652+
* Hash String
653+
*
654+
* @param string $string
655+
* @param int $length
656+
* @param string $type
657+
* @param int $interation
658+
* @return void
659+
*/
660+
static public function stringHash(?string $string = null, $length = 100, $type = 'sha256', $interation = 100)
661+
{
662+
return hash_pbkdf2($type, mt_rand() . $string, self::PBKDF2_SALT, $interation, $length);
616663
}
617664

618665
/**
@@ -641,20 +688,6 @@ static public function shortenString($string = null, $limit = 50, $replacer = '.
641688
return $string;
642689
}
643690

644-
/**
645-
* Clean tags for use in URLs, considering multiple language modules.
646-
*
647-
* @param string|null $string The input string to clean.
648-
* @return string The cleaned string.
649-
*/
650-
static public function cleanTagsForURL(?string $string = null)
651-
{
652-
// Remove unwanted characters from the string
653-
$string = preg_replace('/[^\p{L}\p{N}\s]/u', '', (string) $string);
654-
655-
return trim($string);
656-
}
657-
658691
/**
659692
* Decode entity html strings
660693
*

Traits/ServerTrait.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,40 @@ public static function getServers(?string $mode = null)
157157
return $data[$mode] ?? $data;
158158
}
159159

160+
/**
161+
* cleanServerPath
162+
*
163+
* @param string $path
164+
* @return string
165+
*/
166+
public static function cleanServerPath(?string $path = null)
167+
{
168+
$path = str_replace(
169+
'\\',
170+
'/', trim((string) $path)
171+
);
172+
173+
return rtrim($path, '/') . '/';
174+
}
175+
176+
/**
177+
* Replace path with given string
178+
* \ or /
179+
*
180+
* @param string $path
181+
* @param string $replacer
182+
*
183+
* @return string
184+
*/
185+
public static function pathReplacer(?string $path, $replacer = '/')
186+
{
187+
return str_replace(
188+
['\\', '/'],
189+
$replacer,
190+
$path
191+
);
192+
}
193+
160194
/**
161195
* Create Server Absolute Path
162196
*
@@ -247,39 +281,5 @@ private static function getDirectRootPath()
247281

248282
return $projectRootPath;
249283
}
250-
251-
/**
252-
* cleanServerPath
253-
*
254-
* @param string $path
255-
* @return string
256-
*/
257-
public static function cleanServerPath(?string $path = null)
258-
{
259-
$path = str_replace(
260-
'\\',
261-
'/', trim((string) $path)
262-
);
263-
264-
return rtrim($path, '/') . '/';
265-
}
266-
267-
/**
268-
* Replace path with given string
269-
* \ or /
270-
*
271-
* @param string $path
272-
* @param string $replacer
273-
*
274-
* @return string
275-
*/
276-
public static function pathReplacer(?string $path, $replacer = '/')
277-
{
278-
return str_replace(
279-
['\\', '/'],
280-
$replacer,
281-
$path
282-
);
283-
}
284284

285285
}

0 commit comments

Comments
 (0)