@@ -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 4.4.0 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,88 +462,22 @@ public function isSecure(): bool
457462 * @param App|null $config Optional alternate config to use
458463 *
459464 * @return $this
465+ *
466+ * @deprecated 4.4.0 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
508- /**
509- * @deprecated 4.4.0 Moved to SiteURIFactory.
510- */
511- private function determineHost (App $ config , string $ baseURL ): string
512- {
513- $ host = parse_url ($ baseURL , PHP_URL_HOST );
514-
515- if (empty ($ config ->allowedHostnames )) {
516- return $ host ;
517- }
518-
519- // Update host if it is valid.
520- $ httpHostPort = $ this ->getServer ('HTTP_HOST ' );
521- if ($ httpHostPort !== null ) {
522- [$ httpHost ] = explode (': ' , $ httpHostPort , 2 );
523-
524- if (in_array ($ httpHost , $ config ->allowedHostnames , true )) {
525- $ host = $ httpHost ;
526- }
527- }
528-
529- return $ host ;
530- }
531-
532475 /**
533476 * Returns the URI path relative to baseURL,
534477 * running detection as necessary.
535478 */
536479 public function getPath (): string
537480 {
538- if ($ this ->path === null ) {
539- $ this ->detectPath ($ this ->config ->uriProtocol );
540- }
541-
542481 return $ this ->path ;
543482 }
544483
@@ -972,7 +911,7 @@ public function getFile(string $fileID)
972911 *
973912 * Do some final cleaning of the URI and return it, currently only used in static::_parse_request_uri()
974913 *
975- * @deprecated Use URI::removeDotSegments() directly
914+ * @deprecated 4.1.2 Use URI::removeDotSegments() directly
976915 */
977916 protected function removeRelativeDirectory (string $ uri ): string
978917 {
0 commit comments