public function guessPath()
{
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
$vendorPath = dirname(dirname(__DIR__));
$vendorParent = realpath(dirname($vendorPath));
$rootPath = $this->getProjectRoot($vendorParent);
$const = array();
if ($rootPath) {
$dir = dir($rootPath);
$index = $basepath = false;
while ($d = $dir->read()) {
if ($d == 'index.php') {
$basepath = $rootPath;
$index = $rootPath . DS . 'index.php';
break;
}
if (file_exists($rootPath . DS . $d . DS . 'index.php')) {
$basepath = $rootPath . DS . $d;
$index = $rootPath . DS . $d . DS . 'index.php';
break;
}
}
if ($index && $basepath) {
$content = file_get_contents($index);
if (preg_match_all('/define.*[\'"](\\w+)[\'"].*((?<=[\'"]).+(?=[\'"])|true|false)/im', $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $value) {
$const[$value[1]] = $value[2];
}
if (preg_match('{.*[\'"](.*ThinkPHP.php)[\'"]}', $content, $matches)) {
$think_path = dirname(realpath($basepath . DS . $matches[1]));
$const['THINK_PATH'] = $think_path;
}
if (!file_exists($const['APP_PATH'])) {
$const['APP_PATH'] = realpath($rootPath . DIRECTORY_SEPARATOR . $const['APP_PATH']);
}
}
}
$const['ROOT_PATH'] = $rootPath;
}
return $const;
}