@@ -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
@@ -227,9 +232,9 @@ public function detectLocale($config)
227232 * either provided by the user in the baseURL Config setting, or
228233 * determined from the environment as needed.
229234 *
230- * @deprecated $protocol and $baseURL are deprecated. No longer used.
231- *
232235 * @return void
236+ *
237+ * @deprecated No longer used.
233238 */
234239 protected function detectURI (string $ protocol , string $ baseURL )
235240 {
@@ -447,7 +452,7 @@ public function isSecure(): bool
447452 }
448453
449454 /**
450- * Sets the relative path and updates the URI object .
455+ * Sets the URI path relative to baseURL .
451456 *
452457 * Note: Since current_url() accesses the shared request
453458 * instance, this can be used to change the "current URL"
@@ -457,51 +462,13 @@ public function isSecure(): bool
457462 * @param App|null $config Optional alternate config to use
458463 *
459464 * @return $this
465+ *
466+ * @deprecated This method will be private. The parameter $config is deprecated. No longer used.
460467 */
461468 public function setPath (string $ path , ?App $ config = null )
462469 {
463470 $ this ->path = $ path ;
464471
465- // @TODO remove this. The path of the URI object should be a full URI path,
466- // not a URI path relative to baseURL.
467- $ this ->uri ->setPath ($ path );
468-
469- $ config ??= $ this ->config ;
470-
471- // It's possible the user forgot a trailing slash on their
472- // baseURL, so let's help them out.
473- $ baseURL = ($ config ->baseURL === '' ) ? $ config ->baseURL : rtrim ($ config ->baseURL , '/ ' ) . '/ ' ;
474-
475- // Based on our baseURL and allowedHostnames provided by the developer
476- // and HTTP_HOST, set our current domain name, scheme.
477- if ($ baseURL !== '' ) {
478- $ host = $ this ->determineHost ($ config , $ baseURL );
479-
480- // Set URI::$baseURL
481- $ uri = new URI ($ baseURL );
482- $ currentBaseURL = (string ) $ uri ->setHost ($ host );
483- $ this ->uri ->setBaseURL ($ currentBaseURL );
484-
485- $ this ->uri ->setScheme (parse_url ($ baseURL , PHP_URL_SCHEME ));
486- $ this ->uri ->setHost ($ host );
487- $ this ->uri ->setPort (parse_url ($ baseURL , PHP_URL_PORT ));
488-
489- // Ensure we have any query vars
490- $ this ->uri ->setQuery ($ _SERVER ['QUERY_STRING ' ] ?? '' );
491-
492- // Check if the scheme needs to be coerced into its secure version
493- if ($ config ->forceGlobalSecureRequests && $ this ->uri ->getScheme () === 'http ' ) {
494- $ this ->uri ->setScheme ('https ' );
495- }
496- } elseif (! is_cli ()) {
497- // Do not change exit() to exception; Request is initialized before
498- // setting the exception handler, so if an exception is raised, an
499- // error will be displayed even if in the production environment.
500- // @codeCoverageIgnoreStart
501- exit ('You have an empty or invalid baseURL. The baseURL value must be set in app/Config/App.php, or through the .env file. ' );
502- // @codeCoverageIgnoreEnd
503- }
504-
505472 return $ this ;
506473 }
507474
@@ -535,10 +502,6 @@ private function determineHost(App $config, string $baseURL): string
535502 */
536503 public function getPath (): string
537504 {
538- if ($ this ->path === null ) {
539- $ this ->detectPath ($ this ->config ->uriProtocol );
540- }
541-
542505 return $ this ->path ;
543506 }
544507
0 commit comments