55namespace Tamedevelopers \Support \Traits ;
66
77use ReflectionClass ;
8+ use Tamedevelopers \Support \Env ;
89use Tamedevelopers \Support \Str ;
10+ use Tamedevelopers \Support \UrlHelper ;
911
1012
1113trait ServerTrait{
@@ -112,10 +114,10 @@ static public function formatWithDomainURI($path = null)
112114 *
113115 * @param string|null $mode
114116 * - [optional] get direct info of data
115- * - server|domain|protocol
117+ * - server|domain
116118 *
117119 * @return mixed
118- * - An associative array containing\ server|domain|protocol
120+ * - An associative array containing\ server|domain
119121 */
120122 static public function getServers ($ mode = null )
121123 {
@@ -126,15 +128,11 @@ static public function getServers($mode = null)
126128 $ serverPath = self ::cleanServerPath (
127129 self ::createAbsolutePath ()
128130 );
129-
130- // Replace Document root inside server path
131- $ domainPath = self ::createAbsoluteDomain ($ serverPath );
132-
131+
133132 // Data
134133 $ data = [
135134 'server ' => $ serverPath ,
136- 'domain ' => $ domainPath ['domain ' ],
137- 'protocol ' => $ domainPath ['protocol ' ],
135+ 'domain ' => UrlHelper::url (),
138136 ];
139137
140138 /*
@@ -151,7 +149,6 @@ static public function getServers($mode = null)
151149 $ data = [
152150 'server ' => $ serverData ['server ' ],
153151 'domain ' => $ serverData ['domain ' ],
154- 'protocol ' => $ serverData ['protocol ' ],
155152 ];
156153 }
157154
@@ -197,7 +194,7 @@ static public function pathReplacer($path, $replacer = '/')
197194 *
198195 * @return string
199196 */
200- static private function createAbsolutePath ()
197+ static public function createAbsolutePath ()
201198 {
202199 // get direct root path
203200 $ projectRootPath = self ::getDirectRootPath ();
@@ -211,38 +208,6 @@ static private function createAbsolutePath()
211208 return $ projectRootPath ;
212209 }
213210
214- /**
215- * Create Server Absolute Path
216- * @param string|null $serverPath
217- *
218- * @return array
219- */
220- static private function createAbsoluteDomain ($ serverPath = null )
221- {
222- // Determine the protocol (http or https)
223- $ protocol = Str::lower ($ _SERVER ['HTTPS ' ] ?? null ) !== 'off '
224- ? 'https:// '
225- : 'http:// ' ;
226-
227- // The Document root path
228- $ docRoot = $ _SERVER ['DOCUMENT_ROOT ' ];
229-
230- // Get the server name (hostname)
231- $ serverName = $ _SERVER ['SERVER_NAME ' ] ?? null ;
232-
233- // Replace Document root inside server path
234- $ domainPath = str_replace ($ docRoot , '' , $ serverPath );
235-
236- // trim(string, '/) - Trim forward slash from left and right
237- // we using right trim only
238- $ domainPath = rtrim ((string ) $ domainPath , '/ ' );
239-
240- return [
241- 'domain ' => "{$ protocol }{$ serverName }{$ domainPath }" ,
242- 'protocol ' => $ protocol ,
243- ];
244- }
245-
246211 /**
247212 * Get Root path with vendor helper
248213 *
0 commit comments