@@ -175,7 +175,12 @@ public function __construct($config, ?URI $uri = null, $body = 'php://input', ?U
175175
176176 parent ::__construct ($ config );
177177
178- $ this ->detectURI ($ config ->uriProtocol , $ config ->baseURL );
178+ if ($ uri instanceof SiteURI) {
179+ $ this ->setPath ($ uri ->getRoutePath ());
180+ } else {
181+ $ this ->setPath ($ uri ->getPath ());
182+ }
183+
179184 $ this ->detectLocale ($ config );
180185 }
181186
@@ -225,7 +230,7 @@ public function detectLocale($config)
225230 * either provided by the user in the baseURL Config setting, or
226231 * determined from the environment as needed.
227232 *
228- * @deprecated $protocol and $baseURL are deprecated. No longer used.
233+ * @deprecated No longer used.
229234 */
230235 protected function detectURI (string $ protocol , string $ baseURL )
231236 {
@@ -443,7 +448,7 @@ public function isSecure(): bool
443448 }
444449
445450 /**
446- * Sets the relative path and updates the URI object .
451+ * Sets the URI path relative to baseURL .
447452 *
448453 * Note: Since current_url() accesses the shared request
449454 * instance, this can be used to change the "current URL"
@@ -453,51 +458,13 @@ public function isSecure(): bool
453458 * @param App|null $config Optional alternate config to use
454459 *
455460 * @return $this
461+ *
462+ * @deprecated This method will be private. The parameter $config is deprecated. No longer used.
456463 */
457464 public function setPath (string $ path , ?App $ config = null )
458465 {
459466 $ this ->path = $ path ;
460467
461- // @TODO remove this. The path of the URI object should be a full URI path,
462- // not a URI path relative to baseURL.
463- $ this ->uri ->setPath ($ path );
464-
465- $ config ??= $ this ->config ;
466-
467- // It's possible the user forgot a trailing slash on their
468- // baseURL, so let's help them out.
469- $ baseURL = ($ config ->baseURL === '' ) ? $ config ->baseURL : rtrim ($ config ->baseURL , '/ ' ) . '/ ' ;
470-
471- // Based on our baseURL and allowedHostnames provided by the developer
472- // and HTTP_HOST, set our current domain name, scheme.
473- if ($ baseURL !== '' ) {
474- $ host = $ this ->determineHost ($ config , $ baseURL );
475-
476- // Set URI::$baseURL
477- $ uri = new URI ($ baseURL );
478- $ currentBaseURL = (string ) $ uri ->setHost ($ host );
479- $ this ->uri ->setBaseURL ($ currentBaseURL );
480-
481- $ this ->uri ->setScheme (parse_url ($ baseURL , PHP_URL_SCHEME ));
482- $ this ->uri ->setHost ($ host );
483- $ this ->uri ->setPort (parse_url ($ baseURL , PHP_URL_PORT ));
484-
485- // Ensure we have any query vars
486- $ this ->uri ->setQuery ($ _SERVER ['QUERY_STRING ' ] ?? '' );
487-
488- // Check if the scheme needs to be coerced into its secure version
489- if ($ config ->forceGlobalSecureRequests && $ this ->uri ->getScheme () === 'http ' ) {
490- $ this ->uri ->setScheme ('https ' );
491- }
492- } elseif (! is_cli ()) {
493- // Do not change exit() to exception; Request is initialized before
494- // setting the exception handler, so if an exception is raised, an
495- // error will be displayed even if in the production environment.
496- // @codeCoverageIgnoreStart
497- exit ('You have an empty or invalid baseURL. The baseURL value must be set in app/Config/App.php, or through the .env file. ' );
498- // @codeCoverageIgnoreEnd
499- }
500-
501468 return $ this ;
502469 }
503470
@@ -531,10 +498,6 @@ private function determineHost(App $config, string $baseURL): string
531498 */
532499 public function getPath (): string
533500 {
534- if ($ this ->path === null ) {
535- $ this ->detectPath ($ this ->config ->uriProtocol );
536- }
537-
538501 return $ this ->path ;
539502 }
540503
0 commit comments