Skip to content

Commit 75a35f7

Browse files
update
1 parent 4515b4e commit 75a35f7

File tree

8 files changed

+75
-21
lines changed

8 files changed

+75
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Support Package For PHP, Laravel and PHP Frameworks
137137
* [lastModified](#file-lastmodified)
138138
* [extension](#file-extension)
139139
* [name](#file-name)
140+
* [base](#file-base)
140141
* [mimeType](#file-mimetype)
141142
* [type](#file-type)
142143
* [permissions](#file-permissions)

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"phpmailer/phpmailer": "^6.9",
2323
"filp/whoops": "^2.15",
2424
"ezyang/htmlpurifier": "^4.13",
25-
"composer-plugin-api": "^2.0",
26-
"dompdf/dompdf": "^3.0"
25+
"composer-plugin-api": "^2.0"
2726
},
2827
"extra": {
2928
"class": "Tamedevelopers\\Support\\ComposerPlugin"

src/Asset.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,16 @@ public static function config($path = null, $cache = false, $type = false): void
8181
{
8282
// if not defined
8383
if(!defined('ASSET_BASE_DIRECTORY')){
84-
// url helper class
85-
$urlFromhelper = HttpRequest::host();
8684

87-
// we don't care the configured url address
88-
// prepare a fallback of using combination of full url
89-
if(empty($urlFromhelper)){
90-
$urlFromhelper = HttpRequest::url();
91-
}
85+
// http
86+
$http = HttpRequest::http();
87+
$host = HttpRequest::host();
88+
89+
// url helper class
90+
$urlFromhelper = HttpRequest::url();
9291

9392
// clean http from url
94-
$urlFromhelper = Str::replace(HttpRequest::http(), '', $urlFromhelper);
93+
$urlFromhelper = Str::replace($http, '', $urlFromhelper);
9594

9695
// if base path is set
9796
if(!empty($path)){
@@ -103,7 +102,7 @@ public static function config($path = null, $cache = false, $type = false): void
103102
$baseForUrlPath = $path;
104103

105104
// check if accessed from default ip:address
106-
if(HttpRequest::isIpAccessedVia127Port()){
105+
if(HttpRequest::isIpAccessedViaPrivateLanPort()){
107106
$baseForUrlPath = '';
108107
}
109108

@@ -117,10 +116,10 @@ public static function config($path = null, $cache = false, $type = false): void
117116
'path' => $path,
118117
'server' => self::formatWithBaseDirectory($path),
119118
'domain' => rtrim(
120-
self::cleanServerPath(HttpRequest::http() . $urlFromhelper),
119+
self::cleanServerPath("{$http}{$urlFromhelper}"),
121120
'/'
122121
),
123-
'removeDomain' => HttpRequest::http() . HttpRequest::host()
122+
'removeDomain' => "{$http}{$host}"
124123
]);
125124
}
126125
}

src/Capsule/File.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static function extension(string $path): ?string
173173
}
174174

175175
/**
176-
* Get the file's basename.
176+
* Get the file's name.
177177
*
178178
* @param string $path
179179
* @return string
@@ -183,6 +183,17 @@ public static function name(string $path): string
183183
return pathinfo($path, PATHINFO_FILENAME);
184184
}
185185

186+
/**
187+
* Get the file's basename.
188+
*
189+
* @param string $path
190+
* @return string
191+
*/
192+
public static function base(string $path): string
193+
{
194+
return basename($path);
195+
}
196+
186197
/**
187198
* Get the file's mime type.
188199
*

src/Laravel.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public static function cssDirective()
4646
{
4747
self::initBladeFacades()::directive('css', function ($expression) {
4848
return "<?php
49-
list(\$path, \$class) = array_pad(explode(',', {$expression}, 2), 2, '');
49+
// Put Blade expression into an array so PHP parses arguments correctly
50+
\$arguments = [{$expression}];
51+
52+
// Normalize args and ensure two elements
53+
list(\$path, \$class) = array_pad(\$arguments, 2, '');
54+
5055
\$path = str_replace(['\"', \"'\"], '', \$path);
5156
\$class = str_replace(['\"', \"'\"], '', \$class);
5257
\$assets = tasset(\$path, true, true);
@@ -65,7 +70,12 @@ public static function jsDirective()
6570
{
6671
self::initBladeFacades()::directive('js', function ($expression) {
6772
return "<?php
68-
list(\$path, \$class) = array_pad(explode(',', {$expression}, 2), 2, '');
73+
// Put Blade expression into an array so PHP parses arguments correctly
74+
\$arguments = [{$expression}];
75+
76+
// Normalize args and ensure two elements
77+
list(\$path, \$class) = array_pad(\$arguments, 2, '');
78+
6979
\$path = str_replace(['\"', \"'\"], '', \$path);
7080
\$class = str_replace(['\"', \"'\"], '', \$class);
7181
\$assets = tasset(\$path, true, true);
@@ -84,10 +94,16 @@ public static function svgDirective()
8494
{
8595
self::initBladeFacades()::directive('svg', function ($expression) {
8696
return "<?php
87-
list(\$path, \$class) = array_pad(explode(',', {$expression}, 2), 2, '');
88-
\$path = str_replace(['\"', \"'\"], '', \$path);
89-
\$class = str_replace(['\"', \"'\"], '', \$class);
97+
// Put Blade expression into an array so PHP parses arguments correctly
98+
\$arguments = [{$expression}];
99+
100+
// Normalize args and ensure two elements
101+
list(\$path, \$class) = array_pad(\$arguments, 2, '');
90102
103+
// Clean quotes/whitespace
104+
\$path = trim(str_replace(['\"', \"'\"], '', (string)\$path));
105+
\$class = trim(str_replace(['\"', \"'\"], '', (string)\$class));
106+
91107
\$fullPath = \\Tamedevelopers\\Support\\Tame::stringReplacer(
92108
str_replace(rtrim(domain('')), '', tasset(\$path, false, false))
93109
);

src/Process/HttpRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ public static function isLocalIp()
252252
return (new Collection($localRanges))->startsWith($serverAddr);
253253
}
254254

255+
/**
256+
* Is IP accessed via private LAN port in browser
257+
*
258+
* @return bool
259+
*/
260+
public static function isIpAccessedViaPrivateLanPort()
261+
{
262+
return self::isIpAccessedVia127Port();
263+
}
264+
255265
/**
256266
* Is IP accessed via 127.0.0.1 port in browser
257267
*

src/helpers.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ function tcollect($items = [])
134134
}
135135
}
136136

137+
if (! function_exists('toptional')) {
138+
/**
139+
* Optional Class
140+
*
141+
* @param array|object|null $items
142+
*
143+
* @return \Tamedevelopers\Support\Collections\Collection|mixed
144+
*/
145+
function toptional($items = [])
146+
{
147+
if(!is_array($items) && !is_null($items)){
148+
$items = Server::toArray($items);
149+
}
150+
151+
return new Collection($items);
152+
}
153+
}
154+
137155
if (! function_exists('tmanager')) {
138156
/**
139157
* Manager Class

tests/url.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// URL Helpers
1111

1212

13-
// config_asset('/', true);
13+
config_asset('/', true);
1414

1515
$http = new Http();
1616

@@ -35,7 +35,7 @@
3535
'Host: ' . $http->host(),
3636
'Path: ' . $http->path(),
3737
'Is AJAX: ' . ($http->isAjax() ? 'yes' : 'no'),
38-
'Accessed via 127.0.0.1: ' . ($http->isIpAccessedVia127Port() ? 'yes' : 'no'),
38+
'Accessed via Private Lan - 127.0.0.1: ' . ($http->isIpAccessedViaPrivateLanPort() ? 'yes' : 'no'),
3939
],
4040

4141
[

0 commit comments

Comments
 (0)