3 namespace Friendica\Util;
17 * @param string|null $baseDir The default base path
18 * @param array $server server arguments
20 public function __construct(string $baseDir, array $server = [])
22 $this->baseDir = $baseDir;
23 $this->server = $server;
27 * Returns the base filesystem path of the App
29 * It first checks for the internal variable, then for DOCUMENT_ROOT and
34 * @throws \Exception if directory isn't usable
36 public function getPath()
38 $baseDir = $this->baseDir;
39 $server = $this->server;
41 if ((!$baseDir || !is_dir($baseDir)) && !empty($server['DOCUMENT_ROOT'])) {
42 $baseDir = $server['DOCUMENT_ROOT'];
45 if ((!$baseDir || !is_dir($baseDir)) && !empty($server['PWD'])) {
46 $baseDir = $server['PWD'];
49 $baseDir = self::getRealPath($baseDir);
51 if (!is_dir($baseDir)) {
52 throw new \Exception(sprintf('\'%s\' is not a valid basepath', $baseDir));
59 * Returns a normalized file path
61 * This is a wrapper for the "realpath" function.
62 * That function cannot detect the real path when some folders aren't readable.
63 * Since this could happen with some hosters we need to handle this.
65 * @param string $path The path that is about to be normalized
66 * @return string normalized path - when possible
68 public static function getRealPath($path)
70 $normalized = realpath($path);
72 if (!is_bool($normalized)) {