58 $this->server = $server;
59 if (empty($server[
'DOCUMENT_ROOT'])) {
60 throw new \InvalidArgumentException(
'DOCUMENT_ROOT variable is unavailable.');
62 $this->docRoot = rtrim(str_replace(
'\\',
'/', $server[
'DOCUMENT_ROOT']),
'/');
63 $this->projectRoot = $projectRoot ?: $this->detectProjectRoot();
64 $this->projectRoot = str_replace(
'\\',
'/', $this->projectRoot);
77 private function detectProjectRoot()
79 if (empty($this->server[
'SCRIPT_FILENAME'])) {
80 throw new \InvalidArgumentException(
'Project root cannot be automatically detected.');
82 $haystack = str_replace(
'\\',
'/', dirname($this->server[
'SCRIPT_FILENAME']));
83 $needle =
'/' . $this->getPath();
84 $isSetupApp = preg_match(
'/^(.+?)' . preg_quote($needle,
'/') .
'$/', $haystack, $matches);
98 if (isset($this->server[self::PARAM_NOT_INSTALLED_URL])) {
111 $isProjectInDocRoot =
false !== strpos($this->projectRoot .
'/', $this->docRoot .
'/');
112 if (empty($this->server[
'HTTP_HOST'])) {
114 }
elseif (!$isProjectInDocRoot) {
115 return 'http://' . $this->server[
'HTTP_HOST'] .
'/';
117 return 'http://' . $this->server[
'HTTP_HOST'] . substr($this->projectRoot .
'/', strlen($this->docRoot));
138 return rtrim($projectRoot,
'/') .
'/' . $this->getPath();
148 $setupDir = $this->
getDir($this->projectRoot);
149 $isSubDir =
false !== strpos($setupDir .
'/', $this->docRoot .
'/');
151 $setupDir = rtrim($setupDir,
'/');
152 $lastOccurrence = strrpos($setupDir,
'/pub/setup');
154 if (
false !== $lastOccurrence) {
155 $setupDir = substr_replace($setupDir,
'/setup', $lastOccurrence, strlen(
'/pub/setup'));
158 return $isSubDir && realpath($setupDir);
166 private function getPath()
168 if (isset($this->server[self::PARAM_NOT_INSTALLED_URL_PATH])) {
169 return trim($this->server[self::PARAM_NOT_INSTALLED_URL_PATH],
'/');
static getDistroBaseUrlPath($server)
elseif(isset( $params[ 'redirect_parent']))
const PARAM_NOT_INSTALLED_URL_PATH
__construct($server, $projectRoot='')
const PARAM_NOT_INSTALLED_URL