@@ -44,8 +44,20 @@ public static function getRequest() {
44
44
public $ params ;
45
45
/** The path parameters (GET params) */
46
46
public $ getParams ;
47
+ /** The (context) document root */
48
+ public $ documentRoot ;
49
+ /** The web root as seen by the user, usually '/' or an alias or mapped path from a proxy */
50
+ public $ webRoot ;
51
+ /** The web root as defined by the local web server */
52
+ public $ localWebRoot ;
53
+ /** The web root URI as it can be requested by the user */
54
+ public $ webRootUri ;
47
55
/** The epoch time in seconds when the request was created */
48
56
public $ startTime ;
57
+ /** Usually the document root */
58
+ public $ appRoot ;
59
+ /** relative path from docroot to the app root, usually empty */
60
+ public $ relativeAppPath ;
49
61
50
62
/** The body of the request (intentionally not public) */
51
63
protected $ body ;
@@ -79,6 +91,9 @@ public function __construct() {
79
91
$ this ->webRoot = $ this ->initWebRoot (TRUE );
80
92
$ this ->localWebRoot = $ this ->initWebRoot (FALSE );
81
93
$ this ->webRootUri = $ this ->initWebRootUri ();
94
+ $ this ->appRoot = $ this ->documentRoot ;
95
+ $ this ->relativeAppPath = '' ;
96
+
82
97
$ this ->startTime = time ();
83
98
84
99
// Will be deprecated
@@ -301,6 +316,20 @@ protected function initWebRootUri() {
301
316
$ host = $ this ->host ;
302
317
return $ protocol .':// ' .$ host .$ this ->webRoot ;
303
318
}
304
-
319
+
320
+ /**
321
+ * Initializes the appRoot and relativeAppPath according to the root of the app.
322
+ * The appRoot can differ from document root as it can be installed in a subdir.
323
+ * @param string $appRoot - the application root directory (absolute path)
324
+ */
325
+ public function setAppRoot ($ appRoot ) {
326
+ $ appRootLen = strlen ($ appRoot );
327
+ $ docRootLen = strlen ($ this ->documentRoot );
328
+ if (($ docRootLen < $ appRootLen ) && (strpos ($ appRoot , $ this ->documentRoot ) === 0 )) {
329
+ $ this ->relativeAppPath = substr ($ appRoot , $ docRootLen );
330
+ } else {
331
+ $ this ->relativeAppPath = '' ;
332
+ }
333
+ }
305
334
}
306
335
0 commit comments