@@ -70,31 +70,31 @@ class SiteURI extends URI
7070 */
7171 private string $ routePath ;
7272
73- public function __construct (App $ configApp )
73+ /**
74+ * @param string $relativePath URI path relative to baseURL. May include
75+ * queries or fragments.
76+ */
77+ public function __construct (App $ configApp , string $ relativePath = '' )
7478 {
75- // It's possible the user forgot a trailing slash on their
76- // baseURL, so let's help them out.
77- $ baseURL = rtrim ($ configApp ->baseURL , '/ ' ) . '/ ' ;
78-
79- // Validate baseURL
80- if (filter_var ($ baseURL , FILTER_VALIDATE_URL ) === false ) {
81- throw new ConfigException (
82- 'Config\App::$baseURL is invalid. '
83- );
84- }
85-
86- $ this ->baseURL = $ baseURL ;
79+ $ this ->baseURL = $ this ->normalizeBaseURL ($ configApp );
8780 $ this ->indexPage = $ configApp ->indexPage ;
8881
8982 $ this ->setBaseSegments ();
9083
9184 // Check for an index page
9285 $ indexPage = '' ;
9386 if ($ configApp ->indexPage !== '' ) {
94- $ indexPage = $ configApp ->indexPage . '/ ' ;
87+ $ indexPage = $ configApp ->indexPage ;
88+
89+ // Check if we need a separator
90+ if ($ relativePath !== '' && $ relativePath [0 ] !== '/ ' && $ relativePath [0 ] !== '? ' ) {
91+ $ indexPage .= '/ ' ;
92+ }
9593 }
9694
97- $ tempUri = $ this ->baseURL . $ indexPage ;
95+ $ relativePath = URI ::removeDotSegments ($ relativePath );
96+
97+ $ tempUri = $ this ->baseURL . $ indexPage . $ relativePath ;
9898 $ uri = new URI ($ tempUri );
9999
100100 if ($ configApp ->forceGlobalSecureRequests ) {
@@ -107,7 +107,25 @@ public function __construct(App $configApp)
107107 }
108108 $ this ->applyParts ($ parts );
109109
110- $ this ->setPath ('/ ' );
110+ $ parts = explode ('? ' , $ relativePath );
111+ $ routePath = $ parts [0 ];
112+ $ this ->setRoutePath ($ routePath );
113+ }
114+
115+ private function normalizeBaseURL (App $ configApp ): string
116+ {
117+ // It's possible the user forgot a trailing slash on their
118+ // baseURL, so let's help them out.
119+ $ baseURL = rtrim ($ configApp ->baseURL , '/ ' ) . '/ ' ;
120+
121+ // Validate baseURL
122+ if (filter_var ($ baseURL , FILTER_VALIDATE_URL ) === false ) {
123+ throw new ConfigException (
124+ 'Config\App::$baseURL is invalid. '
125+ );
126+ }
127+
128+ return $ baseURL ;
111129 }
112130
113131 /**
@@ -247,14 +265,22 @@ public function __toString(): string
247265 * @return $this
248266 */
249267 public function setPath (string $ path )
268+ {
269+ $ this ->setRoutePath ($ path );
270+
271+ return $ this ;
272+ }
273+
274+ /**
275+ * Sets the route path (and segments).
276+ */
277+ private function setRoutePath (string $ path ): void
250278 {
251279 $ this ->routePath = $ this ->filterPath ($ path );
252280
253281 $ this ->segments = $ this ->convertToSegments ($ this ->routePath );
254282
255283 $ this ->refreshPath ();
256-
257- return $ this ;
258284 }
259285
260286 /**
0 commit comments