Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit ee41a01

Browse files
committed
updated
1 parent 2224c92 commit ee41a01

File tree

5 files changed

+61
-39
lines changed

5 files changed

+61
-39
lines changed

src/Exception/Exception.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/**
3+
* @format
4+
*/
25

36
namespace PhpSlides;
47

@@ -33,7 +36,7 @@ public function getDetailedMessage(): string
3336
'Error: %s in %s on line %d',
3437
$this->getMessage(),
3538
$file,
36-
$line
39+
$line,
3740
);
3841
}
3942

@@ -45,44 +48,51 @@ public function getDetailedMessage(): string
4548
public function filterStackTrace(): array
4649
{
4750
/**
48-
/**
49-
* This filter removes all file paths that come from the vendor folders.
50-
*/
51+
* This filter removes all file paths that come from the vendor folders.
52+
*/
53+
54+
/*
5155
$majorFilter = array_filter($this->getTrace(), function ($item) {
5256
$ss = strpos($item['file'], '/vendor/') === false;
5357
$sss = strpos($item['file'], '\vendor\\') === false;
5458
5559
return $ss && $sss === true;
5660
});
61+
*/
5762

5863
/**
5964
* This filter adds only file paths from the vendor folders.
6065
*/
66+
67+
/*
6168
$minorFilter = array_filter($this->getTrace(), function ($item) {
6269
$ss = strpos($item['file'], '/vendor/') !== false;
6370
$sss = strpos($item['file'], '\vendor\\') !== false;
6471
6572
return $ss || $sss === true;
6673
});
74+
*/
6775

6876
/**
6977
* Create a new array and merge them together.
7078
* Major filters first, then the minor filters.
7179
*/
80+
81+
/*
7282
$majorFilterValue = array_values($majorFilter);
7383
$minorFilterValue = array_values($minorFilter);
7484
$newFilter = array_merge($majorFilterValue, $minorFilterValue);
85+
*/
7586

7687
/**
7788
* Replace generated views files to the corresponding view
7889
*/
7990
$newFilter = array_map(function ($item) {
8091
$item['file'] = str_replace('.g.php', '.php', $item['file']);
8192
$item['file'] = str_replace('.g.psl', '.psl', $item['file']);
82-
$item['file'] = str_replace('.g.view.php', '.view.php', $item['file']);
8393

8494
return $item;
85-
}, $newFilter);
95+
}, $this->getTrace());
8696

8797
return $newFilter;
8898
}
@@ -133,7 +143,7 @@ public function getCodeSnippet($linesBefore = 10, $linesAfter = 10): array
133143
file: $file,
134144
line: $line,
135145
linesBefore: $linesBefore,
136-
linesAfter: $linesAfter
146+
linesAfter: $linesAfter,
137147
);
138148
}
139149
}

src/Formatter/Views/FormatHotReload.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/**
3+
* @format
4+
*/
25

36
namespace PhpSlides\Formatter\Views;
47

@@ -46,7 +49,7 @@ protected function hot_reload()
4649
// Get session ID and PhpSlides version
4750
$sid = session_id();
4851
$phpslides_version = Application::PHPSLIDES_VERSION;
49-
$host = $protocol . $_SERVER['HTTP_HOST'] . "/hot-reload-$sid";
52+
$host = $protocol . $_SERVER['HTTP_HOST'] . "/hot-reload-a$sid";
5053

5154
// Check if HOT_RELOAD is enabled in the environment
5255
if (getenv('HOT_RELOAD') == 'true') {
@@ -73,7 +76,7 @@ protected function hot_reload()
7376
}, 1000);
7477
</script>\n
7578
</body>",
76-
$this->contents
79+
$this->contents,
7780
);
7881
}
7982

src/Foundation/Application.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
/**
3+
* @format
4+
*/
5+
declare(strict_types=1);
26

37
namespace PhpSlides\Foundation;
48

@@ -96,12 +100,15 @@ private static function configure(): void
96100
{
97101
if (php_sapi_name() == 'cli-server') {
98102
self::$request_uri = urldecode(
99-
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
103+
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
100104
);
101105
self::$basePath = '';
102106
} else {
103107
self::$request_uri = urldecode(
104-
parse_url($_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'], PHP_URL_PATH)
108+
parse_url(
109+
$_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'],
110+
PHP_URL_PATH,
111+
),
105112
);
106113
self::$basePath = '../../';
107114
}
@@ -140,7 +147,7 @@ public function create(): void
140147
$sid = session_id();
141148

142149
if (getenv('HOT_RELOAD') == 'true') {
143-
Route::post("/hot-reload-$sid", fn() => (new HotReload())->reload());
150+
Route::post("/hot-reload-a$sid", fn() => (new HotReload())->reload());
144151
}
145152

146153
try {

src/Globals/Chunks/trace.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
*
4+
* @format
55
* @param array $trace
66
* @return array
77
*/
@@ -10,6 +10,7 @@ function filterTrace(array $trace)
1010
/**
1111
* This Filter and removes all file path that is coming from the vendor folders
1212
*/
13+
1314
$majorFilter = array_filter($trace, function ($item) {
1415
$ss = strpos($item['file'] ?? '', '/vendor/') === false;
1516
$sss = strpos($item['file'] ?? '', '\vendor\\') === false;
@@ -20,6 +21,7 @@ function filterTrace(array $trace)
2021
/**
2122
* This filters and add only file path from the vendor folders
2223
*/
24+
2325
$minorFilter = array_filter($trace, function ($item) {
2426
$ss = strpos($item['file'] ?? '', '/vendor/') !== false;
2527
$sss = strpos($item['file'] ?? '', '\vendor\\') !== false;
@@ -32,6 +34,7 @@ function filterTrace(array $trace)
3234
* Major filters first
3335
* Then the Minor filters follows
3436
*/
37+
3538
$majorFilterValue = array_values($majorFilter);
3639
$minorFilterValue = array_values($minorFilter);
3740
$newFilter = array_merge($majorFilterValue, $minorFilterValue);
@@ -43,7 +46,6 @@ function filterTrace(array $trace)
4346
if (array_key_exists('file', $item)) {
4447
$item['file'] = str_replace('.g.php', '.php', $item['file']);
4548
$item['file'] = str_replace('.g.psl', '.psl', $item['file']);
46-
$item['file'] = str_replace('.g.view.php', '.view.php', $item['file']);
4749
}
4850

4951
return $item;

src/Http/Request.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
/**
3+
* @format
4+
*/
5+
declare(strict_types=1);
26

37
namespace PhpSlides\Http;
48

@@ -65,15 +69,11 @@ public function urlParam(?string $key = null): object|string
6569
public function urlQuery(?string $name = null): stdClass|string
6670
{
6771
if (php_sapi_name() == 'cli-server') {
68-
$parsed = urldecode(
69-
parse_url($this->server('REQUEST_URI'), PHP_URL_QUERY)
70-
);
72+
$parsed = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
7173
} else {
72-
$parsed = urldecode(
73-
parse_url(
74-
$_REQUEST['uri'] ?? $this->server('REQUEST_URI'),
75-
PHP_URL_QUERY
76-
)
74+
$parsed = parse_url(
75+
$_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'],
76+
PHP_URL_QUERY,
7777
);
7878
}
7979

@@ -82,7 +82,7 @@ public function urlQuery(?string $name = null): stdClass|string
8282
if (!$parsed) {
8383
return $cl;
8484
}
85-
$parsed = mb_split('&', $parsed);
85+
$parsed = mb_split('&', urldecode($parsed));
8686

8787
$i = 0;
8888
while ($i < count($parsed)) {
@@ -297,7 +297,7 @@ public function session(?string $key = null): mixed
297297
*/
298298
public function method(): string
299299
{
300-
return $this->server('REQUEST_METHOD');
300+
return $_SERVER['REQUEST_METHOD'];
301301
}
302302

303303
/**
@@ -336,10 +336,10 @@ public function url(): object
336336
public function ip(): string
337337
{
338338
// Check for forwarded IP addresses from proxies or load balancers
339-
if ($this->server('HTTP_X_FORWARDED_FOR') !== null) {
340-
return $this->server('HTTP_X_FORWARDED_FOR');
339+
if ($_SERVER['HTTP_X_FORWARDED_FOR'] !== null) {
340+
return $_SERVER['HTTP_X_FORWARDED_FOR'];
341341
}
342-
return $this->server('REMOTE_ADDR');
342+
return $_SERVER['REMOTE_ADDR'];
343343
}
344344

345345
/**
@@ -351,7 +351,7 @@ public function ip(): string
351351
*/
352352
public function userAgent(): string
353353
{
354-
return $this->server('HTTP_USER_AGENT');
354+
return $_SERVER['HTTP_USER_AGENT'];
355355
}
356356

357357
/**
@@ -363,7 +363,7 @@ public function userAgent(): string
363363
*/
364364
public function isAjax(): bool
365365
{
366-
return $this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest';
366+
return $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
367367
}
368368

369369
/**
@@ -373,8 +373,8 @@ public function isAjax(): bool
373373
*/
374374
public function referrer(): ?string
375375
{
376-
return $this->server('HTTP_REFERER') !== null
377-
? $this->server('HTTP_REFERER')
376+
return $_SERVER['HTTP_REFERER'] !== null
377+
? $_SERVER['HTTP_REFERER']
378378
: null;
379379
}
380380

@@ -385,7 +385,7 @@ public function referrer(): ?string
385385
*/
386386
public function protocol(): string
387387
{
388-
return $this->server('SERVER_PROTOCOL');
388+
return $_SERVER['SERVER_PROTOCOL'];
389389
}
390390

391391
/**
@@ -411,7 +411,7 @@ public function server(?string $key = null): mixed
411411
if (!$key) {
412412
return $this->validate($_SERVER);
413413
}
414-
return isset($_SERVER[$key]) ? $this->validate($_SERVER[$key]) : null;
414+
return $_SERVER[$key] !== null ? $this->validate($_SERVER[$key]) : null;
415415
}
416416

417417
/**
@@ -432,7 +432,7 @@ public function isMethod(string $method): bool
432432
*/
433433
public function isHttps(): bool
434434
{
435-
return isset($this->server('HTTPS')) && $this->server('HTTPS') === 'on';
435+
return $_SERVER['HTTPS'] !== null && $_SERVER['HTTPS'] === 'on';
436436
}
437437

438438
/**
@@ -442,7 +442,7 @@ public function isHttps(): bool
442442
*/
443443
public function requestTime(): int
444444
{
445-
return $this->server('REQUEST_TIME');
445+
return $_SERVER['REQUEST_TIME'];
446446
}
447447

448448
/**
@@ -466,8 +466,8 @@ public function contentType(): ?string
466466
*/
467467
public function contentLength(): ?int
468468
{
469-
return $this->server('CONTENT_LENGTH') !== null
470-
? (int) $this->server('CONTENT_LENGTH')
469+
return $_SERVER['CONTENT_LENGTH'] !== null
470+
? (int) $_SERVER['CONTENT_LENGTH']
471471
: null;
472472
}
473473
}

0 commit comments

Comments
 (0)