Skip to content

Commit 4bd9508

Browse files
author
Fredrick Peter
committed
update
1 parent d664a46 commit 4bd9508

File tree

4 files changed

+214
-163
lines changed

4 files changed

+214
-163
lines changed

Cookie.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ class Cookie{
4040

4141
/**
4242
* Create Sitename From .env
43-
* - APP_NAME
4443
*
4544
* @return $this
4645
*/
4746
static protected function init()
4847
{
49-
self::$name = strtolower(str_replace([' '], '', $_ENV['APP_NAME']));
48+
self::$name = strtolower(str_replace([' '], '', env('APP_NAME')));
5049
self::$timeName = "__time_" . self::$name;
5150
self::$expireName = "__expire_" . self::$name;
5251
self::$timeFormat = Time::timestamp('next year', 'Y-m-d');
@@ -60,7 +59,7 @@ static protected function init()
6059
* @param string $name
6160
* - Cookie Name
6261
*
63-
* @param string|null
62+
* @param string|null $value
6463
* - Cookie Value
6564
*
6665
* @param int|string $minutes
@@ -89,13 +88,13 @@ static protected function init()
8988
* If setcookie successfully runs, it will return true.
9089
* This does not indicate whether the user accepted the cookie.
9190
*/
92-
static public function set($name, $value, $minutes = 0, $path = null, $domain = null, $secure = null, $httponly = null, $force = null)
91+
static public function set($name, $value = null, $minutes = 0, $path = null, $domain = null, $secure = null, $httponly = null, $force = null)
9392
{
9493
// minutes
9594
$minutes = self::minutesToExpire($minutes);
9695

9796
// create default values
98-
[$path, $domain, $secure, $httponly, $force] = self::getDefaultPathAndDomain($path, $domain, $secure, $httponly, $force);
97+
[$path, $value, $domain, $secure, $httponly, $force] = self::getDefaultPathAndDomain($path, $value, $domain, $secure, $httponly, $force);
9998

10099
// set cookie
101100
if ( !headers_sent() || $force === true) {
@@ -114,8 +113,7 @@ static public function set($name, $value, $minutes = 0, $path = null, $domain =
114113
static public function forget($name, $path = null, $domain = null)
115114
{
116115
self::set(
117-
name: $name,
118-
value: '',
116+
name: $name,
119117
minutes: 'last year',
120118
path: $path,
121119
domain: $domain,
@@ -245,16 +243,18 @@ static private function minutesToExpire($minutes = 0)
245243
* Get the path and domain, or the default values.
246244
*
247245
* @param string|null $path
246+
* @param string|null $value
248247
* @param string|null $domain
249248
* @param bool|null $secure
250249
* @param bool|null $httponly
251250
* @param bool|null $force
252251
* @return array
253252
*/
254-
static private function getDefaultPathAndDomain($path = null, $domain = null, $secure = null, $httponly = null, $force = null)
253+
static private function getDefaultPathAndDomain($path = null, $value = null, $domain = null, $secure = null, $httponly = null, $force = null)
255254
{
256255
return [
257256
!empty($path) ? $path : '/',
257+
!empty($value) ? $value : '',
258258
!empty($domain) ? $domain : '',
259259
is_bool($secure) ? $secure : false,
260260
is_bool($httponly) ? $httponly : false,

Laravel.php

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,79 @@
1313
*/
1414
class Laravel{
1515

16+
1617
/**
17-
* Create SVG Directrives
18-
*
19-
* @usage @svg('path_to_svg')
20-
*
21-
* @return mixed
18+
* Register a Blade directive
19+
*
20+
* @return void
2221
*/
23-
static public function svgDirective()
22+
public function cssDirective()
2423
{
25-
Tame::class_exists('Illuminate\Support\Facades\Blade', function(){
24+
Blade::directive('css', function ($expression) {
25+
list($path, $class) = array_pad(explode(',', $expression, 2), 2, '');
2626

27-
// Register a Blade directive
28-
Blade::directive('svg', function ($expression) {
27+
$path = str_replace(['"', "'"], '', $path);
28+
$class = str_replace(['"', "'"], '', $class);
2929

30-
list($path, $class) = array_pad(explode(',', $expression, 2), 2, '');
30+
// fullpath
31+
$assets = asset($path, true);
3132

32-
$path = str_replace(['"', "'"], '', $path);
33-
$class = str_replace(['"', "'"], '', $class);
33+
return "<link rel='stylesheet' type='text/css' href='{$assets}'>";
34+
});
35+
}
36+
37+
/**
38+
* Register a Blade directive
39+
*
40+
* @return void
41+
*/
42+
public function jsDirective()
43+
{
44+
Blade::directive('js', function ($expression) {
45+
list($path, $class) = array_pad(explode(',', $expression, 2), 2, '');
46+
47+
$path = str_replace(['"', "'"], '', $path);
48+
$class = str_replace(['"', "'"], '', $class);
49+
50+
// fullpath
51+
$assets = asset($path, true);
52+
53+
return "<script src='{$assets}'></script>";
54+
});
55+
}
56+
57+
/**
58+
* Register a Blade directive
59+
*
60+
* @return mixed
61+
*/
62+
public function svgDirective()
63+
{
64+
Blade::directive('svg', function ($expression) {
65+
list($path, $class) = array_pad(explode(',', $expression, 2), 2, '');
66+
67+
$path = str_replace(['"', "'"], '', $path);
68+
$class = str_replace(['"', "'"], '', $class);
69+
70+
// fullpath
71+
$fullPath = public_path($path);
72+
73+
// if file exists
74+
if(Tame::exists($fullPath)){
3475

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-
};
58-
});
76+
$svg = new \DOMDocument();
77+
$svg->load($fullPath);
78+
79+
// If a class is provided, add it to the SVG element
80+
if (!empty($class)) {
81+
$svg->documentElement->setAttribute("class", $class);
82+
}
83+
84+
$output = $svg->saveXML($svg->documentElement);
85+
86+
// Return the modified SVG
87+
return $output;
88+
};
5989
});
6090
}
6191

0 commit comments

Comments
 (0)