3 namespace Friendica\Util;
8 * @brief Returns the base filesystem path of the App
10 * It first checks for the internal variable, then for DOCUMENT_ROOT and
13 * @param string|null $basePath The default base path
14 * @param array $server server arguments
18 * @throws \Exception if directory isn't usable
20 public static function create($basePath, array $server = [])
22 if ((!$basePath || !is_dir($basePath)) && !empty($server['DOCUMENT_ROOT'])) {
23 $basePath = $server['DOCUMENT_ROOT'];
26 if ((!$basePath || !is_dir($basePath)) && !empty($server['PWD'])) {
27 $basePath = $server['PWD'];
30 $basePath = self::getRealPath($basePath);
32 if (!is_dir($basePath)) {
33 throw new \Exception(sprintf('\'%s\' is not a valid basepath', $basePath));
40 * @brief Returns a normalized file path
42 * This is a wrapper for the "realpath" function.
43 * That function cannot detect the real path when some folders aren't readable.
44 * Since this could happen with some hosters we need to handle this.
46 * @param string $path The path that is about to be normalized
47 * @return string normalized path - when possible
49 public static function getRealPath($path)
51 $normalized = realpath($path);
53 if (!is_bool($normalized)) {