Skip to content

Commit e760337

Browse files
committed
#12 - Add appRoot capability
1 parent 25b77ed commit e760337

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/TgUtils/Request.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public static function getRequest() {
4444
public $params;
4545
/** The path parameters (GET params) */
4646
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;
4755
/** The epoch time in seconds when the request was created */
4856
public $startTime;
57+
/** Usually the document root */
58+
public $appRoot;
59+
/** relative path from docroot to the app root, usually empty */
60+
public $relativeAppPath;
4961

5062
/** The body of the request (intentionally not public) */
5163
protected $body;
@@ -79,6 +91,9 @@ public function __construct() {
7991
$this->webRoot = $this->initWebRoot(TRUE);
8092
$this->localWebRoot = $this->initWebRoot(FALSE);
8193
$this->webRootUri = $this->initWebRootUri();
94+
$this->appRoot = $this->documentRoot;
95+
$this->relativeAppPath = '';
96+
8297
$this->startTime = time();
8398

8499
// Will be deprecated
@@ -301,6 +316,20 @@ protected function initWebRootUri() {
301316
$host = $this->host;
302317
return $protocol.'://'.$host.$this->webRoot;
303318
}
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+
}
305334
}
306335

0 commit comments

Comments
 (0)