X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FBasePath.php;h=3d5a23727809a9023d29807c4e9e08a6c46e7392;hb=204e52ea307b182175ae0c64d6eb69c71a104658;hp=f29c2e864ec414b7d1219344e4e14d6fd0b622f9;hpb=c1f99c70b1c7d62120723f3b142e843ba25ab338;p=friendica.git diff --git a/src/Util/BasePath.php b/src/Util/BasePath.php index f29c2e864e..3d5a237278 100644 --- a/src/Util/BasePath.php +++ b/src/Util/BasePath.php @@ -1,43 +1,81 @@ . + * + */ namespace Friendica\Util; class BasePath { /** - * @brief Returns the base filesystem path of the App + * @var string + */ + private $baseDir; + /** + * @var array + */ + private $server; + + /** + * @param string|null $baseDir The default base path + * @param array $server server arguments + */ + public function __construct(string $baseDir, array $server = []) + { + $this->baseDir = $baseDir; + $this->server = $server; + } + + /** + * Returns the base filesystem path of the App * * It first checks for the internal variable, then for DOCUMENT_ROOT and * finally for PWD * - * @param string|null $basePath The default base path - * @param array $server server arguments - * * @return string * * @throws \Exception if directory isn't usable */ - public static function create($basePath, array $server = []) + public function getPath() { - if ((!$basePath || !is_dir($basePath)) && !empty($server['DOCUMENT_ROOT'])) { - $basePath = $server['DOCUMENT_ROOT']; + $baseDir = $this->baseDir; + $server = $this->server; + + if ((!$baseDir || !is_dir($baseDir)) && !empty($server['DOCUMENT_ROOT'])) { + $baseDir = $server['DOCUMENT_ROOT']; } - if ((!$basePath || !is_dir($basePath)) && !empty($server['PWD'])) { - $basePath = $server['PWD']; + if ((!$baseDir || !is_dir($baseDir)) && !empty($server['PWD'])) { + $baseDir = $server['PWD']; } - $basePath = self::getRealPath($basePath); + $baseDir = self::getRealPath($baseDir); - if (!is_dir($basePath)) { - throw new \Exception(sprintf('\'%s\' is not a valid basepath', $basePath)); + if (!is_dir($baseDir)) { + throw new \Exception(sprintf('\'%s\' is not a valid basepath', $baseDir)); } - return $basePath; + return $baseDir; } /** - * @brief Returns a normalized file path + * Returns a normalized file path * * This is a wrapper for the "realpath" function. * That function cannot detect the real path when some folders aren't readable.